3 ms·
Even though they are included in the GNU C library, most people do not seem to know about Obstacks: An "obstack" is a pool of memory containing a stack of obje
by teddyh 13y ago
Even though they are included in the GNU C library, most people do not seem to know about Obstacks:
An "obstack" is a pool of memory containing a stack of objects. You
can create any number of separate obstacks, and then allocate objects in
specified obstacks. Within each obstack, the last object allocated must
always be the first one freed, but distinct obstacks are independent of
each other.
Aside from this one constraint of order of freeing, obstacks are
totally general: an obstack can contain any number of objects of any
size. They are implemented with macros, so allocation is usually very
fast as long as the objects are usually small. And the only space
overhead per object is the padding needed to start each object on a
suitable boundary.
https://www.gnu.org/software/libc/manual/html_node/Obstacks.html https://www.gnu.org/software/libc/manual/html_node/Obstacks....
Sure, they’re not very interesting, but the point is that you get them for free in the GNU C standard library.
- dllthomas 13y agoThe FIFO equivalent can also be useful.
- teddyh 13y agoI’m not sure what you are referring to, do you have a link?
- deleted 13y ago[deleted]
- deleted 13y ago[deleted]
- dllthomas 13y agoI don't have a link, but it's an obvious transformation - basically, using a ring buffer for allocations where I can guarantee that older things will be freed before newer stuff.