template <typename T, size_t kDataBits, bool kCheckAlignment = true>

class PackedPointer

Defined at line 56 of file ../../zircon/system/ulib/fbl/include/fbl/packed_pointer.h

PackedPointer

<T

, kDataBits, kCheckAlignment> is a pointer wrapper that allows

storing a small amount of data in the alignment bits of the pointer.

The number of bits available for packing (kDataBits) must be less than or

equal to the number of trailing zero bits in the alignment of T. For example,

if alignof(T) == 8, then kDataBits can be up to 3.

PackedPointer provides a safety check at compile time to ensure that the

requested number of data bits is compatible with the alignment of T. It also

provides runtime assertions (in debug builds) to ensure that the pointer

passed to it is correctly aligned and that the data fits within the specified

number of bits.

In some cases, such as when T is an incomplete type (e.g. when PackedPointer

is used as a member of T), the compile-time alignment check cannot be

performed. In these cases, kCheckAlignment can be set to false to disable

the check.

Example usage:

struct alignas(8) MyStruct { ... };

PackedPointer

<MyStruct

, 3> ptr(my_struct_instance, 0x5);

MyStruct* p = ptr.ptr(); // returns my_struct_instance

uintptr_t d = ptr.data(); // returns 0x5

Public Members

static const uintptr_t kDataMask
static const uintptr_t kPtrMask

Public Methods

void PackedPointer<T, kDataBits, kCheckAlignment> ()

Defined at line 66 of file ../../zircon/system/ulib/fbl/include/fbl/packed_pointer.h

void PackedPointer<T, kDataBits, kCheckAlignment> (std::nullptr_t )

Defined at line 67 of file ../../zircon/system/ulib/fbl/include/fbl/packed_pointer.h

void PackedPointer<T, kDataBits, kCheckAlignment> (T * ptr)

Defined at line 69 of file ../../zircon/system/ulib/fbl/include/fbl/packed_pointer.h

void PackedPointer<T, kDataBits, kCheckAlignment> (T * ptr, uintptr_t data)

Defined at line 80 of file ../../zircon/system/ulib/fbl/include/fbl/packed_pointer.h

void PackedPointer<T, kDataBits, kCheckAlignment> (std::nullptr_t , uintptr_t data)

Defined at line 87 of file ../../zircon/system/ulib/fbl/include/fbl/packed_pointer.h

T * ptr ()

Defined at line 91 of file ../../zircon/system/ulib/fbl/include/fbl/packed_pointer.h

uintptr_t data ()

Defined at line 92 of file ../../zircon/system/ulib/fbl/include/fbl/packed_pointer.h

void set_ptr (T * ptr)

Defined at line 94 of file ../../zircon/system/ulib/fbl/include/fbl/packed_pointer.h

void set_data (uintptr_t data)

Defined at line 102 of file ../../zircon/system/ulib/fbl/include/fbl/packed_pointer.h

void reset ()

Defined at line 107 of file ../../zircon/system/ulib/fbl/include/fbl/packed_pointer.h

T & operator* ()

Pointer semantics

Defined at line 110 of file ../../zircon/system/ulib/fbl/include/fbl/packed_pointer.h

T * operator-> ()

Defined at line 111 of file ../../zircon/system/ulib/fbl/include/fbl/packed_pointer.h

bool operator bool ()

Defined at line 112 of file ../../zircon/system/ulib/fbl/include/fbl/packed_pointer.h

bool operator== (const PackedPointer<T, kDataBits, kCheckAlignment> & other)

Comparison operators

Defined at line 115 of file ../../zircon/system/ulib/fbl/include/fbl/packed_pointer.h

bool operator!= (const PackedPointer<T, kDataBits, kCheckAlignment> & other)

Defined at line 116 of file ../../zircon/system/ulib/fbl/include/fbl/packed_pointer.h

bool operator== (std::nullptr_t )

Defined at line 117 of file ../../zircon/system/ulib/fbl/include/fbl/packed_pointer.h

bool operator!= (std::nullptr_t )

Defined at line 118 of file ../../zircon/system/ulib/fbl/include/fbl/packed_pointer.h