4 ms·
Ah, but that pointer doesn't get re-used on you until you free it, and for that there are strategies like refcounting and GC. Integers in a small array will ge
by kazinator 6y ago
Ah, but that pointer doesn't get re-used on you until you free it, and for that there are strategies like refcounting and GC.
Integers in a small array will get re-used; they have to.
- andolanra 6y agoYou should probably read the whole article, because it describes strategies for dealing with exactly this problem in the section under Memory safety considerations and then again in the update at the end. The short form is: if you have a bounded size on your array, then you will often have unused bits in your index pointer; you can use these to store a "generation counter", which needs to match the slot. You can now re-use indices, because you can compare the generation of the index (stored in the extra bits) with the generation count in the slot, and if they match, it means that the item has been 'freed' and a new thing is in the slot.
- deleted 6y ago[deleted]