3 ms·
When I need to avoid an allocation it's because I'm writing an allocator :) Overlaying the list nodes on top of a block of free memory avoids the need for a sec
by docandrew 4y ago
When I need to avoid an allocation it's because I'm writing an allocator :) Overlaying the list nodes on top of a block of free memory avoids the need for a secondary data structure to keep track of free areas.
The other time allocations are undesirable, and therefore linked lists are widely-used, is bare metal work when other allocators just aren't available. You can do tricks like representing pools of free and in-use objects with two lists where the nodes occupy the same memory block. Allocations are a fast O(1) unlink from the free list and O(1) re-link to the used list, and frees are the opposite.