What are the real life use cases for tagged pointers?
This is mostly coming from reading about small 64-bit systems and possible uses of 64-bit word pointers.
To my understanding tagged pointers are addresses which can containing extra information in bits due to possible address space on that particular architecture is much smaller.
But then, is it possible to use tagged pointers beyond trivial cases? Any cool ideas / examples?
Are there popular libraries, frameworks taking advantage of 64-bit pointers via tagged pointers? Is that possible on every hardware?
6
The critbit trie library uses tagged pointers to differentiate between internal and external nodes in the trie. By ensuring that new nodes are allocated aligned to a certain value you are guaranteed that some of the lower bits of the address are zero, the number of which depends on the alignment you require. You can then store other info in these bits… in the case of critbit nodes the LSB is set if the node is external (a leaf). Just remember to untag the address if you intend to use it.
It saves having an extra member variable in the node structure.
1