c++ - Adding a 1 bit flag in a 64 bit pointer -


if define union traversing data structure squentially (start , end offset) or via pointer tree structure depending on number of data elements on 64 bit system these unions aligned cache lines, there possibility of both adding 1 bit flag @ 1 of 64 bits in order know traversal must used , still allowing reconstruct right pointer?

union {     uint32_t offsets[2];     tree<nodedata> * tree; }; 

it's system dependent, don't think 64-bit system uses full pointer-length yet.
also, if know data 2n-aligned, chances n bits sitting idle there (on old systems not exist. don't think of 64-bit systems, , anyway no longer of interest).

as example, x86_64 uses 48bits, upper 16 must same bit47. (sign-extended)
example, arm64 uses 49bits (2 mappings of 48bit @ same time), there have 15 bits left.

just remember corect pilfered bits. (you might want use uintptr_t instead of pointer, , convert after correction.)

using mis-aligned or impossible pointer causes behavior ranging silent auto-correction, ranging on silent mis-behavior, loud crashes.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -