Pointer Tagging in C++: The Art of Packing Bits Into a Pointer
A 64-bit pointer can address over 18 exabytes (18 billion gigabytes) of memory, which far exceeds the needs of even the most top-end supercomputers1. For this reason, most modern desktop CPUs only use 48 bits for virtual addresses2, leaving the upper 16 bits unused.The bottom bits are typically underutilized, too. Most malloc implementations align allocations to 16-byte boundaries, so the bottom four bits are always set to zero. These bottom four bits can be repurposed to store extra data, as lo...
Read more at vectrx.substack.com