View source code Display the source code in std/bitmanip.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Enum std.bitmanip.member taggedPointer

This string mixin generator allows one to create tagged pointers inside structs and classes.

A tagged pointer uses the bits known to be zero in a normal pointer or class reference to store extra information. For example, a pointer to an integer must be 4-byte aligned, so there are 2 bits that are always known to be zero. One can store a 2-bit integer there.

The example above creates a tagged pointer in the struct A. The pointer is of type uint* as specified by the first argument, and is named x, as specified by the second argument.

Following arguments works the same way as bitfield's. The bitfield must fit into the bits known to be zero because of the pointer alignment.

Warning: Don't use taggedPointer with pointers to garbage collected objects, as it will result in undefined behaviour. See http://dlang.org/garbage.html for details.

Declaration

enum taggedPointer(T, string name, Ts...) = createTaggedReference!(createStoreName!(T, name, 0, Ts), T*, T.alignof, name, Ts).result;

Example

struct A
{
    int a;
    mixin(taggedPointer!(
        uint*, "x",
        bool, "b1", 1,
        bool, "b2", 1));
}
A obj;
obj.x = new uint;
obj.b1 = true;
obj.b2 = false;

Authors

Walter Bright, Andrei Alexandrescu, Jonathan M Davis, Alex Rønne Petersen, Damian Ziemba Amaury SECHET

License

Boost License 1.0.

Comments