[Idea] Bitmask for valid pointer bits

I’m not sure if this is possible for all targets and platforms, and i’m not sure if it’s worth it. (And not urgent at all, only a possibility )

When allocator allocates, the resulting * mut (), when cast to an usize value, might not use up all bits available. While it differs a lot according to the allocator, i think it can remain consistent during the whole program execution.

If we can retrieve this information somehow, it can lay a solid foundation for tagged pointers. I think it may be accessed as a constant, or retrieved from the allocator API?

The number of bits is implied by the alignment that you request for the allocation.

1 Like

There’s also an implicit minimum alignment in most allocators.

And the size of a pointer varies by platform (obviously)…

Personally, I think it could be cool, but I would rather it be implemented as a separate crate. I could imagine having something like this:

trait TaggedPointer: Deref + DerefMut;

struct x86_32BitTaggedPointer(* mut u8);
impl TaggedPointer for x86_32BitTaggedPointer { ... }

struct x86_64BitTaggedPointer(* mut u8);
impl TaggedPointer for x86_64BitTaggedPointer { ... }


tagged pointer have different schemes. some use least significant bits(which is implied by the alignment, yeah), some use most significant bits(if they’re available).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.