Live data from Hacker News

Collections-C, generic data structures for C

github.com

11–20 of 63 posts

Re: Collections-C, generic data structures for C

#11
post #5

I try and plug http://concurrencykit.org/ whenever I see someone looking for something like this. It's built around providing portable atomic intrinsics for parallel code, but the data structures are also very well done and work just as nicely for single threaded code.

Does it include any sort of a concurrent heap into shared memory?

Re: Collections-C, generic data structures for C

#13
post #6
post #4

Has 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.

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.

Re: Collections-C, generic data structures for C

#14
post #7
post #2

It 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.

Start using arenas wherever you can. Makes memory management in C programs substantially simpler.

Any good readings on getting started with arenas?

Re: Collections-C, generic data structures for C

#17
A quick look shows this is storing void* pointers only. My excitement was quickly over as I was expecting something with _Generic macros or ability to manage memory for any type.

https://github.com/srdja/Collections-C/blob/master/src/hasht... shows the container is manually configurable. Look at the defines at the bottom. This would mean the container file source-header pair, would have to be duplicated for every type, which is somewhat manageable.

Why isn't this written in the readme?

Re: Collections-C, generic data structures for C

#18
post #7

Earlier quoted context omitted.

Start using arenas wherever you can. Makes memory management in C programs substantially simpler.

Any good readings on getting started with arenas?

Yes. This book (free online): http://www.smallmemory.com/book.html

http://www.smallmemory.com/6_AllocationChapter.pdf

Re: Collections-C, generic data structures for C

#19
post #6

Earlier 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.

Even then you'd want proper logging and panicking over a segfault (the likely result).
Post reply on HN