|
Xarn posted:Orrrr you can use std::lock, which afaik guarantees no deadlocks when acquiring multiple mutexes.
|
# ? Jan 23, 2022 01:01 |
|
|
# ? Jun 8, 2024 00:14 |
|
No? std::lock() is "repeatedly lock(), unlock(), and try_lock() in some unspecified order until you have all the locks". Practical implementation is like: while you don't have all the locks: - try_lock() them until you either have them all or one fails - if you have them all, return - release all the ones you did get - do a blocking lock() for the one that was unavailable It fills a different purpose than a naive "Lock #1, do work, lock #2, do more work, unlock #2, unlock #1", but it won't crash or deadlock
|
# ? Jan 23, 2022 01:32 |
|
You do have to design around being to use std::lock — it acquires all the locks simultaneously — so it wouldn’t work on the wrapper; you’d need a variadic with function.
|
# ? Jan 23, 2022 01:35 |
|
Does visual studio have those annotations? I think that would be great for me to learn.
|
# ? Jan 23, 2022 01:45 |
|
baby puzzle posted:Does visual studio have those annotations? I think that would be great for me to learn. MSVC as a compiler does have a concurrency analyzer with a similar (E: but more limited, to be clear) set of annotations to gcc and clang's __attribute__((acquired_before(...))) and co. This blogpost was the best reference for it I could find. Not sure if MS are hiding a better overview somewhere else. If you just mean Visual Studio as an IDE then their clang support is reportedly OK nowadays. There's a "clang tools for windows" option in the installer, that should get you a sufficiently recent version of clang that the attributes just work. I have no idea how well the debugging and inspection works compared to "native" MSVC, never used it myself. Also I expect that a fair few libraries will check the wrong #define, assume that you're compiling with MSVC anyhow, and explode in fun and interesting ways.
|
# ? Jan 23, 2022 02:59 |
|
Apart from a few incorrect analyzer intellisense warnings - a squiggly warning about throwing with exceptions disabled when they’re not being disabled anywhere, for example - the clang toolchain works well in VS in my experience. The debugger works fine and all that.
|
# ? Jan 23, 2022 08:05 |
|
So I put an entire text file of numbers into a string and want to take those numbers out of the string and put it into an array. Is their an easy way of doing that?
|
# ? Jan 24, 2022 08:18 |
|
drilldo squirt posted:So I put an entire text file of numbers into a string and want to take those numbers out of the string and put it into an array. Is their an easy way of doing that? are they delimited by a character or fixed width? If it's the former, the readline function in the standard library lets you specify a delimiter other than the newline character. If it's the latter, just doing index math is probably the easiest.
|
# ? Jan 24, 2022 08:23 |
|
drilldo squirt posted:So I put an entire text file of numbers into a string and want to take those numbers out of the string and put it into an array. Is their an easy way of doing that? C or C++? C++: https://en.cppreference.com/w/cpp/string/basic_string/stol and a vector? C: strtol and realloc?
|
# ? Jan 24, 2022 14:31 |
|
Does anybody have a recommendation for a C (not C++) container library that has: 1. Containers for vector (or arraylist depending on back group), a hash table/map, and doubly-linked lists 2. Ability to specify custom allocator/free 3. A permissive license where we don't have to release source code There's a bunch out there and I was going to just check a few out by default, but I figured I'd ask and see if I can whittle it down.
|
# ? Jan 24, 2022 23:15 |
|
Rocko Bonaparte posted:Does anybody have a recommendation for a C (not C++) container library that has: stb
|
# ? Jan 25, 2022 01:07 |
|
drilldo squirt posted:So I put an entire text file of numbers into a string and want to take those numbers out of the string and put it into an array. Is their an easy way of doing that? If C++ and space delimited and only includes numbers, you could just use an istream to read stuff in. Should reduce supporting code. C++ code:
|
# ? Jan 25, 2022 05:09 |
|
Thanks.
|
# ? Jan 25, 2022 22:05 |
|
Any of you fine folks have any recommendations for implementing debug messages such as some lightweight (haha) header library? Something along the lines of "categories" I guess where I want x or y or z type events to output or just x for example. Standard output is fine, I don't need to log this stuff into a DB.
|
# ? Jan 29, 2022 20:55 |
|
Maybe spdlog might help?
|
# ? Jan 29, 2022 21:14 |
|
log4cxx
|
# ? Jan 29, 2022 21:22 |
|
I'm coding a small game as a hobby project, where buildings produce and distribute goods between eachother. The player can inspect several reports based on that data. Those transactions between buildings are stored as structs and gathered in a big bad std::vector. A report then "queries" that data by running a visitor function over that vector. Whenever I build a new report, I write a new function and often a whole new class and stuff. I'd just like to throw an SQL-Query at that data instead. But, as said, it's just a simple vector full of structs. In C# i'd look into LINQ. Any suggestions for something similar in C++? I'm not completly sure if this is the right place, just tell me to go away if it isn't. Wipfmetz fucked around with this message at 13:19 on Jan 31, 2022 |
# ? Jan 31, 2022 13:14 |
|
It’s been a long time since I used LINQ but if I remember right, at the end of the day LINQ is about creating anonymous functions (lambdas) to do the work and applying them over the collection you give it. Are you looking for nicer syntax than what you’ve got today or better functionality around aggregate functions and grouping?
|
# ? Jan 31, 2022 14:46 |
|
You could just go whole hog and integrate SQLite?
|
# ? Jan 31, 2022 15:18 |
|
csammis posted:It’s been a long time since I used LINQ but if I remember right, at the end of the day LINQ is about creating anonymous functions (lambdas) to do the work and applying them over the collection you give it. Are you looking for nicer syntax than what you’ve got today or better functionality around aggregate functions and grouping? I'd prefer a nicer syntax since to actually convey what I'm doing with the data in a concise matter, and SQL-ey syntax is good at that. And that would include aggregating and grouping. ynohtna posted:You could just go whole hog and integrate SQLite? "SQLite is an in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.". Hm, sounds interesting and worth a shot, thank you. I'd see this as a "go whole hog"-option, which I'll go to if/when I see more things where I'd want to throw SQL at. Wipfmetz fucked around with this message at 16:17 on Jan 31, 2022 |
# ? Jan 31, 2022 15:24 |
|
Wipfmetz posted:In C# i'd look into LINQ. Any suggestions for something similar in C++? i don't think you're going to find something with the same flexibility as linq to objects in C#. i think the choices are either suck it up and just write the code, or not use c++ for that portion of the game - you could just have the report be a webview (and use something like chrome embedded framework to embed it in your game.)
|
# ? Jan 31, 2022 19:53 |
|
There are almost certainly ways to make writing the functions feel less laborious, though, if that’s the problem. You’re probably duplicating a ton of code instead of extracting out little composable operations that you can re-use for different queries.
|
# ? Jan 31, 2022 20:33 |
|
I was trying to use that std_ds.h for dynamic arrays and hashtables for some Linux kernel code. I had to replace the default memory management with my own realloc and free so it would use vmalloc and vfree. That was the easy part. The hard part came in trying to copying the old data into the newer buffer. I just have the pointer to the old buffer without knowing how large it is, so I don't know how much to copy over, and using the new size is going to blow a hole in my foot if it's larger. Since I have multiples of these data structures, I can't just assume any particular size. Is there anything I can use to determine the size of the allocated pointer given the base address? I see in vmalloc.h find_vm_area, but I don't know if that symbol is actually exported for kernel modules. I couldn't seem to link to it despite starting right at the header my target kernel is using. The std_ds.h file has some notion of an unused context variable it's passing around to these calls but it's just NULL for now. I could try to do something with it if I had to, but that's going to be some serious surgery and I'd rather avoid it if I could.
|
# ? Feb 10, 2022 07:15 |
|
It's a good bet that any system for dynamically-sized arrays will be stashing both the current size and the capacity of the current allocation somewhere, so that it knows when it's going to need to realloc. Why not just use that information instead of trying to track the size of your current memory allocation separately?
|
# ? Feb 10, 2022 09:47 |
|
The implementation is not my own and the hook I have is for changing realloc and free. I wanted to try to stay in that lane first before ripping the file apart to try to pass in more info.
|
# ? Feb 10, 2022 15:49 |
|
If you're using the same stb_ds.h that I found, the pointer it passes to realloc literally points to a header struct containing the existing size and capacity.
|
# ? Feb 10, 2022 16:14 |
|
Yeah it's that and yes it looks like I have to just play with that header. Having slept on it, I went on a grepping spree in vmalloc and found nothing that I think I could use to get the length. There's some stuff in the vmalloc header but none of it is actually exported outside of the file (no EXPORT_SYMBOL macros for them). So don't mind me everybody, and apologies in advance if a stray fragment of a concrete block comes flying out of the monitor. That's just me over here with a wrecking ball, messing with that header muahahaha.
|
# ? Feb 10, 2022 16:41 |
|
Why aren’t you using the kernel’s existing hash tables and dynamic arrays?
|
# ? Feb 10, 2022 16:43 |
|
It's a fair question. I want alternative versions that also work in userspace so I can run a lot of my testing in normal userspace unit testing frameworks. I originally actually was using the linked list and hash tables that way. However, I had hence modified kernel code and that put me in an LGPL quagmire with my workplace, so I needed to start from a less restrictive license. Also, I hate my life.
|
# ? Feb 10, 2022 17:27 |
|
Using GNU autotools, what is the best practice for managing config.sub and config.guess? Should they be checked into the repository at all? I'm updating a project that uses GNU autotools so that it will build and run on the new macs. It has config.guess and config.sub checked into the project, but running autoreconf -fi did not do anything to update them. I'm coming at this with very little existing autotools knowledge, so basically all that I know is that these scripts are used to standardize strings about the specific platform and architecture, and older versions won't have any knowledge of aarch64 Macs. I hacked through this by copying in the copies of config.guess and config.sub that were installed with my system automake, at /opt/homebrew/Cellar/automake/1.16.5/share/automake-1.16/ because I installed autotools with homebrew. Is there some way to set up autotools to use the system config.sub and config.guess instead of checking it into the project? This is basically all that I can find as far as official documentation: https://www.gnu.org/software/gettext/manual/html_node/config_002eguess.html Twerk from Home fucked around with this message at 17:32 on Feb 11, 2022 |
# ? Feb 11, 2022 17:20 |
|
There don't appear to have been any apple silicon-related changes to config.sub or config.guess. The intended use of autotools is that building the project doesn't require having autotools installed, and the project should include all of the generated files in its distribution package. If the git repository is the primary way for users to get the project, that implies they should be committed to the repository.
|
# ? Feb 11, 2022 18:13 |
|
Plorkyeran posted:There don't appear to have been any apple silicon-related changes to config.sub or config.guess. Interesting that it's not Apple silicon related, when I ran ./configure without replacing the config.sub and config.guess, I saw this: pre:checking build system type... configure: error: /bin/sh ./config.sub -apple-darwin21.3.0 failed pre:$ src/config.sub -apple-darwin21.3.0 config.sub: invalid option -apple-darwin21.3.0 Try `config.sub --help' for more information.
|
# ? Feb 11, 2022 19:11 |
|
That was incidentally fixed by a change in 2004 which made it no longer have a hardcoded list of possible processors. autoreconf -ivf should be overwriting the existing config.guess and config.sub files with the up-to-date ones. If it's not, you can also try running automake --add-missing --copy --force-missing directly. Copying them over manually is fine too if you don't feel like trying to debug why autotools isn't doing the right thing (but you probably will need to regenerate the configure script with a modern version of autoconf and if automake isn't working that might not be either).
|
# ? Feb 11, 2022 19:44 |
|
Plorkyeran posted:That was incidentally fixed by a change in 2004 which made it no longer have a hardcoded list of possible processors. Sweet! I had run autoreconf -ivf and it did not replace them. It did update the configure script, and put me into a state where I had a new configure script and old, broken config.sub and .guess. Thanks!
|
# ? Feb 11, 2022 19:47 |
|
It looks like I'll be trying to retrofit a cmake project to work with an older version and I'm pretty new to the tool. I already see some stuff that came up running against an older version of the tool that is pretty inside-baseball to me. Is there a good resource for doing the basics while not necessarily hiding the whats and where of certain details? I was going to default to the online Mastering CMake c/o https://cmake.org/cmake/help/book/mastering-cmake/, but I can also hit O'Reilly stuff through work for free.
|
# ? Feb 12, 2022 03:19 |
|
There are several guides listed in the docs and Professional CMake is pretty much the CMake bible imo
|
# ? Feb 12, 2022 04:09 |
|
Trying to port a nontrivial cmake project to an older version of cmake sounds like a very horrifying project and I would try very hard to find any other possible solution.
|
# ? Feb 12, 2022 04:26 |
|
Plorkyeran posted:Trying to port a nontrivial cmake project to an older version of cmake sounds like a very horrifying project and I would try very hard to find any other possible solution.
|
# ? Feb 12, 2022 05:29 |
|
Plorkyeran posted:Trying to port a nontrivial cmake project to an older version of cmake sounds like a very horrifying project and I would try very hard to find any other possible solution. This is 99% correct, the remaining 1% is if it is one of those cases where the cmake_minimum_required or w/e was just set to latest and doesn't actually need it.
|
# ? Feb 12, 2022 11:58 |
|
|
# ? Jun 8, 2024 00:14 |
|
Point taken. I may be able to get around it but at this point I'm dumber than a brick with CMake. I think either way that I'd have to modify this build environment no matter what I do and I can't even add a library dependency yet out of just ignorance. If trying to backport to an old version ends up like this after the first pass then I need to step back and consider some other method.qsvui posted:There are several guides listed in the docs and Professional CMake is pretty much the CMake bible imo I'll see about getting Profession CMake. The tutorial was doing a decent job of the basic syntax but wasn't getting my into the grit with some of the magic stuff they were setting and what it meant. Like, I was able to Google what they were but couldn't understand what they meant from that, so I needed to back up a bit.
|
# ? Feb 13, 2022 06:12 |