3 ms·
A union is perfectly fine, the next element is only needed when the element is in the free list in which case item_t won't be accessed.
by gpderetta 7y ago
A union is perfectly fine, the next element is only needed when the element is in the free list in which case item_t won't be accessed.
- zenogais 7y agoIt should work fine in the examples, but it won't work if you also attempt to use the -1 in the next slot to tell you which items are non-free.
- gpderetta 7y agoIf you want to iterate through your objects without some external mean to track the live objects (like an embedded next pointer in the object itself), then the swap and pop idiom is a better solution (iterating via indexing is going to be significantly faster than following the next pointers).