RFC: tagged pointer

bearophile via Digitalmars-d digitalmars-d at puremagic.com
Wed Oct 8 01:23:17 PDT 2014


deadalnix:

> There is something that is badly needed in std.butmanip : a way 
> to create tagged pointers. It is doable safely by checking 
> pointer alignment and allowing for n bits to be taken for 
> various things.

It can't be used for GC-managed pointers. A possible usage syntax:

enum Tag1 { A, B, C, D }
alias TP1 = TaggedPointer!Tag1; // Uses 2 bits.
enum Tag2 { A, B }
alias TP2 = TaggedPointer!Tag2; // Uses 1 bit.
enum Tag3 { A, B, C, D, E } // 5 possibilities
alias TP3 = TaggedPointer!Tag3; // Uses 3 bits.

Alternative name "TaggedPtr".
It should verify some things statically about the given enum.

I wrote a tagged pointer struct in D1 to implement a more 
memory-succinct Trie (I think the tag was one bit, to tell apart 
nodes the terminate a word from the other nodes). But now I can't 
find the source code...

Bye,
bearophile


More information about the Digitalmars-d mailing list