3 ms·
Here's a stupid question: what's the difference of using an intrusive container against using an STL container of (probably smart) pointers? i.e. std::list<My c
by ktpsns 6y ago
Here's a stupid question: what's the difference of using an intrusive container against using an STL container of (probably smart) pointers? i.e. std::list<My class*>. I've done that plenty of times in my codes in the past.
- huhtenberg 6y agoAdding/removing items to std::list will result in extra allocations/deallocations. It will also take up more space, to store that very pointer. All of which starts to matter (a lot) when operating with very large data sets.
- humanrebar 6y agoAn intrusive node has a getter for the next intrusive node. And the data structure would use that getter to organize the elements of the data structure. Among other implications (different memory locality and allocation guarantees), you could have the same intrusive node object used in several container objects or even classes (though not at the same time). That is, pull an element from a doubly linked list and insert it into a binary tree without reallocation.
- zackees 6y agoWith intrusive you can remove from the list in constant time from the object itself. With std::list you need to find the iterate to the node before you can delete it.