Get the latest tech news
Pointer Tagging in C++: The Art of Packing Bits into a Pointer
Using tagged pointers to save memory, speed up dynamic dispatch, and compact data structures
For this article, we’ll assume a 48-bit canonical address space (though keep in mind that this detail is platform-dependent), giving us 16 high bits to work with. At run-time, a switch statement casts the pointer to the correct type before calling the corresponding “virtual” function — not far off from what was shown in this article! These spare bits can be repurposed to store additional information, enabling more compact data layouts and reducing the cost of run-time polymorphism.
Or read this on Hacker News