Discussion:
RFC: tagged pointer
deadalnix via Digitalmars-d
2014-10-08 05:13:49 UTC
Permalink
Hi all,

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.

This is something I want to do for ages (and need) but constantly
run out of time. I think it would be useful to others as well.

Would someone champion it ?
bearophile via Digitalmars-d
2014-10-08 08:23:17 UTC
Permalink
Post by deadalnix via Digitalmars-d
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

Continue reading on narkive:
Loading...