xenium
Public Member Functions | List of all members
xenium::marked_ptr< T, MarkBits, MaxUpperMarkBits > Class Template Reference

A pointer with an embedded mark/tag value. More...

#include <marked_ptr.hpp>

Public Member Functions

 marked_ptr (T *p=nullptr, uintptr_t mark=0) noexcept
 Construct a marked_ptr with an optional mark value. More...
 
void reset () noexcept
 Reset the pointer to nullptr and the mark to 0.
 
uintptr_t mark () const noexcept
 Get the mark value.
 
T * get () const noexcept
 Get underlying pointer (with mark bits stripped off).
 
 operator bool () const noexcept
 True if get() != nullptr || mark() != 0
 
T * operator-> () const noexcept
 Get pointer with mark bits stripped off.
 
T & operator* () const noexcept
 Get reference to target of pointer.
 

Detailed Description

template<class T, uintptr_t MarkBits, uintptr_t MaxUpperMarkBits = XENIUM_MAX_UPPER_MARK_BITS>
class xenium::marked_ptr< T, MarkBits, MaxUpperMarkBits >

A pointer with an embedded mark/tag value.

Acts like a pointer, but has an embeded mark/tag value with MarkBits bits. On most systems pointers are only 48-bit, leaving the 16 topmost bits clear. Therefore, the mark value is usually embeded in these top-most bits. For mark mark values that exceed MaxUpperMarkBits bits the remaining bits are embedded in the lowest bits, but this requires the pointer to be aligned properly.

Template Parameters
T
MarkBitsthe number of bits used for the mark value
MaxUpperMarkBitsthe max number of bits to be used (defaults to 16)

Constructor & Destructor Documentation

◆ marked_ptr()

template<class T , uintptr_t MarkBits, uintptr_t MaxUpperMarkBits = XENIUM_MAX_UPPER_MARK_BITS>
xenium::marked_ptr< T, MarkBits, MaxUpperMarkBits >::marked_ptr ( T *  p = nullptr,
uintptr_t  mark = 0 
)
inlinenoexcept

Construct a marked_ptr with an optional mark value.

The mark value is automatically trimmed to MarkBits bits.