đź“ťTagged pointer

Tagged pointer is a technique to pack additional information into a pointer value.

If all allocations are 4- or 8-bytes aligned, the low 2 or 3 bytes are always zero. Language runtime can use this information to cram additional information into a pointer—i.e., tag what pointer value actually means.

Example:

  • 2 low bits are 0: the value is pointer

  • 1 low bit is 1: the value is 31-bit integer (assuming 32-bit pointers), or the value is 32-bit integer stored in upper half

  • the lowest 2 bits are 10: 30 other bits mean something else

See also

Backlinks