per at bothner.com
Tue Oct 16 02:43:44 CEST 2018
On 10/15/18 3:47 PM, Andy Green wrote:
> It's indeed similar, but obstacks troubles itself to track the sub-allocations
I pretty sure it doesn't - unless we're talking about different things.
> "...When all the objects in a chunk become free, the obstack library automatically frees the chunk (see Preparing for Obstacks). Then other obstacks, or non-obstack allocation, can reuse the space of the chunk. ..."
> lwsac has literally zero overhead for aligned sub-allocations in the chunks... a million individual void * just take up the space of a million void * plus the per-chunk overhead you can control by selecting the chunk size.
Likewise with obstacks.
> There is no "objects in a chunk become free", they are allocated for the lifetime of the lwsac. Only the lwsac itself gets freed.
> It's not as flexible as individual object malloc (obstacks, since it lets you free objects, demanding tracking overhead is just a variety of that) but for cases where you weren't going to destroy anything in this container until you were going to destroy the container, it's potentially very advantageous. There's no per-object overhead and no destroy unwinding, plus it can grow as needed like obstacks.
Obstack's "tracking" is just the "high-water mark" of lwsac. "Freeing" an object just means adjusting the
high-water mark to an old value - plus freeing any chunks allocated since.
per at bothner.com http://per.bothner.com/
More information about the Libwebsockets