[Idea] Bitmask for valid pointer bits

#1

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?

0 Likes

#2

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

1 Like

#3

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

0 Likes

#4

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 { ... }

...
0 Likes

#5

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).

0 Likes

closed #6

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

0 Likes