Earlier quoted context omitted.
But for this kind of application, wouldn't you just panic and do a soft restart on malloc failure anyway? Actually recovering from an out-of-memory situation is incredibly fraught and unreliable; most of the realtime operating systems I've used don't even bother to try.
Even then you'd want proper logging and panicking over a segfault (the likely result).
Collections-C, generic data structures for C
21–30 of 63 posts
Re: Collections-C, generic data structures for C
#22J/K
Re: Collections-C, generic data structures for C
#23It looks like all collections store void pointers. I don't see any abstractions to help with pointer lifetimes, which remains the main problem I encounter when trying to write large programs in C that dynamically allocate memory.
Re: Collections-C, generic data structures for C
#24It's C.
Why on Earth you'd want to allocate a separate list node for each piece of data when you can embed this node directly into the data and then use container_of or similar offsetof() derivative to get a pointer to the data by a pointer to a list item? Saves you at least sizeof(void*) per item and eliminates a chance of list_add ever failing among other things.
The same goes for custom allocators - why would you drag around pointers to malloc, calloc and free, when all you need is just a pointer to realloc?
This sort of thing. The code is nice, but it's not how one would write a container library after few years of hands-on C experience.
Re: Collections-C, generic data structures for C
#25Has this library been stress tested? I am interested in using this library for a spaceflight application, but reliability is paramount in our situation.
I stopped looking when I saw it doesn't check for malloc failure. I am going to say space flight is a no-go.
Any recommendations for reliable C data structures?
Re: Collections-C, generic data structures for C
#26Has this library been stress tested? I am interested in using this library for a spaceflight application, but reliability is paramount in our situation.
I stopped looking when I saw it doesn't check for malloc failure. I am going to say space flight is a no-go.
Re: Collections-C, generic data structures for C
#27If you don't want to use this style of programming, for whatever reason, check out sys/queue.h. It's already on your system, if you're using some kind of Unix.
Re: Collections-C, generic data structures for C
#28Re: Collections-C, generic data structures for C
#29It looks like all collections store void pointers. I don't see any abstractions to help with pointer lifetimes, which remains the main problem I encounter when trying to write large programs in C that dynamically allocate memory.
I'm no expert here, just curious. I've seen this brought up a couple times now: what's wrong with void pointers? How else would you do this in C? If you wanted abstractions to help with pointer lifetimes wouldn't you just be better off using C++?
Sometimes you just don't have the option of a C++ compiler. Also, and this was a situation I was in recently, I needed a collection in a small area of my C code so it really didn't warrant a toolset change.
Re: Collections-C, generic data structures for C
#30Earlier quoted context omitted.
I stopped looking when I saw it doesn't check for malloc failure. I am going to say space flight is a no-go.
But for this kind of application, wouldn't you just panic and do a soft restart on malloc failure anyway? Actually recovering from an out-of-memory situation is incredibly fraught and unreliable; most of the realtime operating systems I've used don't even bother to try.
If we have a failure during rendezvous with our target, it could be a very bad day.