2 ms·
One of the only times linked lists are "undoubtedly the right option" is if you're writing some sort of intrusive data structure to avoid an allocation by reusi
by ComputerGuru 4y ago
One of the only times linked lists are "undoubtedly the right option" is if you're writing some sort of intrusive data structure to avoid an allocation by reusing caller stack from another location. Not sure how many run into that often.
- docandrew 4y agoWhen 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.