Skip to content

iox::rp::BaseRelativePointer🔗

pointer class to use when pointer and pointee are located in different shared memory segments We can have the following scenario: Pointer p is stored in segment S1 and points to object X of type T in segment S2. More...

#include <base_relative_pointer.hpp>

Inherited by iox::rp::RelativePointer< T >, iox::rp::RelativePointer< Index_t >, iox::rp::RelativePointer< iox_sem_t >

Public Types🔗

Name
using uint64_t id_t
using void * ptr_t
using const void *const const_ptr_t
using std::uintptr_t offset_t

Public Functions🔗

Name
BaseRelativePointer(ptr_t ptr, id_t id)
constructs a BaseRelativePointer pointing to the same pointee as ptr in a segment identified by id
BaseRelativePointer(offset_t offset, id_t id)
constructs a BaseRelativePointer from a given offset and segment id
BaseRelativePointer(ptr_t ptr =nullptr)
constructs a BaseRelativePointer pointing to the same pointer as ptr
BaseRelativePointer(const BaseRelativePointer & other)
copy constructor
BaseRelativePointer(BaseRelativePointer && other)
move constructor
BaseRelativePointer & operator=(const BaseRelativePointer & other)
copy assignment
BaseRelativePointer & operator=(void * ptr)
assigns the BaseRelativePointer to point to the same pointee as ptr
BaseRelativePointer & operator=(BaseRelativePointer && other)
move assignment
ptr_t get() const
access to the underlying object
id_t getId() const
returns the id which identifies the segment
offset_t getOffset() const
returns the offset
ptr_t getBasePtr() const
get the base pointer associated with this' id
offset_t computeOffset(ptr_t ptr) const
get the offset from the start address of the segment and ptr
ptr_t computeRawPtr() const
get the pointer from stored id and offset
id_t registerPtr(const ptr_t ptr, uint64_t size =0U)
registers a memory segment at ptr with size of a new id
bool registerPtr(const id_t id, const ptr_t ptr, uint64_t size =0U)
tries to register a memory segment with a given size starting at ptr to a given id
bool unregisterPtr(const id_t id)
unregisters ptr with given id
ptr_t getBasePtr(const id_t id)
get the base ptr associated with the given id
void unregisterAll()
unregisters all ptr id pairs (leads to initial state)
offset_t getOffset(const id_t id, const_ptr_t ptr)
get the offset from id and ptr
ptr_t getPtr(const id_t id, const offset_t offset)
get the pointer from id and offset ("inverse" to getOffset)
id_t searchId(ptr_t ptr)
get the id for a given ptr
bool isValid(id_t id)
checks if given id is valid
PointerRepository< id_t, ptr_t > & getRepository()
returns the pointer repository

Public Attributes🔗

Name
constexpr id_t NULL_POINTER_ID
constexpr offset_t NULL_POINTER_OFFSET

Protected Attributes🔗

Name
id_t m_id
offset_t m_offset

Detailed Description🔗

class iox::rp::BaseRelativePointer;

pointer class to use when pointer and pointee are located in different shared memory segments We can have the following scenario: Pointer p is stored in segment S1 and points to object X of type T in segment S2.

Note: It should be noted that relocating a memory segment will invalidate relative pointers, i.e. relative pointers are NOT relocatable. This is because the registration mechanism cannot be automatically informed about the copy of a whole segment, such a segment would have to be registered on its own (and the original segment deregistered).

Shared Memory S1: p S2: X |_______^ App1 a1 b1 c1 d1 App2 a2 b2 c2 d2

Now it is no longer true in general that both segments will be offset by the same difference in App2 and therefore relocatable pointers are no longer sufficient. Relative pointers solve this problem by incorporating the information from where they need to measure differences (i.e. relative to the given address). This requires an additional registration mechanism to be used by all applications where the start addresses and the size of all segments to be used are registered. Since these start address may differ between applications, each segment is identified by a unique id, which can be provided upon registration by the first application. In the figure, this means that the starting addresses of both segments(a1, a2 and c1, c2) would have to be registered in both applications. Once this registration is done, relative pointers can be constructed from raw pointers similar to relocatable pointers.

Public Types Documentation🔗

using id_t🔗

using iox::rp::BaseRelativePointer::id_t =  uint64_t;

using ptr_t🔗

using iox::rp::BaseRelativePointer::ptr_t =  void*;

using const_ptr_t🔗

using iox::rp::BaseRelativePointer::const_ptr_t =  const void* const;

using offset_t🔗

using iox::rp::BaseRelativePointer::offset_t =  std::uintptr_t;

Public Functions Documentation🔗

function BaseRelativePointer🔗

BaseRelativePointer(
    ptr_t ptr,
    id_t id
)

constructs a BaseRelativePointer pointing to the same pointee as ptr in a segment identified by id

Parameters:

  • ptr the pointer whose pointee shall be the same for this
  • id is the unique id of the segment

function BaseRelativePointer🔗

BaseRelativePointer(
    offset_t offset,
    id_t id
)

constructs a BaseRelativePointer from a given offset and segment id

Parameters:

  • offset is the offset
  • id is the unique id of the segment

function BaseRelativePointer🔗

BaseRelativePointer(
    ptr_t ptr =nullptr
)

constructs a BaseRelativePointer pointing to the same pointer as ptr

Parameters:

  • ptr the pointer whose pointee shall be the same for this

function BaseRelativePointer🔗

BaseRelativePointer(
    const BaseRelativePointer & other
)

copy constructor

Parameters:

  • other is the copy origin

function BaseRelativePointer🔗

BaseRelativePointer(
    BaseRelativePointer && other
)

move constructor

Parameters:

  • other is the move origin

function operator=🔗

BaseRelativePointer & operator=(
    const BaseRelativePointer & other
)

copy assignment

Parameters:

  • other is the copy origin

Return: a reference to self

function operator=🔗

BaseRelativePointer & operator=(
    void * ptr
)

assigns the BaseRelativePointer to point to the same pointee as ptr

Parameters:

  • ptr the pointer whose pointee shall be the same for this

Return: reference to self

function operator=🔗

BaseRelativePointer & operator=(
    BaseRelativePointer && other
)

move assignment

Parameters:

  • other is the move origin

Return: a reference to self

function get🔗

ptr_t get() const

access to the underlying object

Return: a pointer to the underlying object

function getId🔗

id_t getId() const

returns the id which identifies the segment

Return: the id which identifies the segment

function getOffset🔗

offset_t getOffset() const

returns the offset

Return: the offset

function getBasePtr🔗

ptr_t getBasePtr() const

get the base pointer associated with this' id

Return: the registered base pointer

function computeOffset🔗

offset_t computeOffset(
    ptr_t ptr
) const

get the offset from the start address of the segment and ptr

Parameters:

  • ptr is the pointer whose offset should be calculated

Return: offset

function computeRawPtr🔗

ptr_t computeRawPtr() const

get the pointer from stored id and offset

Return: the pointer for stored id and offset

function registerPtr🔗

static id_t registerPtr(
    const ptr_t ptr,
    uint64_t size =0U
)

registers a memory segment at ptr with size of a new id

Parameters:

  • ptr starting address of the segment to be registered
  • size is the size of the segment

Return: id it was registered to

function registerPtr🔗

static bool registerPtr(
    const id_t id,
    const ptr_t ptr,
    uint64_t size =0U
)

tries to register a memory segment with a given size starting at ptr to a given id

Parameters:

  • id is the id of the segment
  • ptr starting address of the segment to be registered
  • size is the size of the segment

Return: true if successful (id not occupied), false otherwise

function unregisterPtr🔗

static bool unregisterPtr(
    const id_t id
)

unregisters ptr with given id

Parameters:

  • id is the id of the segment

Return: true if successful (ptr was registered with this id before), false otherwise

function getBasePtr🔗

static ptr_t getBasePtr(
    const id_t id
)

get the base ptr associated with the given id

Parameters:

  • id is the id of the segment

Return: ptr registered at the given id, nullptr if none was registered

function unregisterAll🔗

static void unregisterAll()

unregisters all ptr id pairs (leads to initial state)

function getOffset🔗

static offset_t getOffset(
    const id_t id,
    const_ptr_t ptr
)

get the offset from id and ptr

Parameters:

  • id is the id of the segment and is used to get the base pointer
  • ptr is the pointer whose offset should be calculated

Return: offset

function getPtr🔗

static ptr_t getPtr(
    const id_t id,
    const offset_t offset
)

get the pointer from id and offset ("inverse" to getOffset)

Parameters:

  • id is the id of the segment and is used to get the base pointer
  • offset is the offset for which the pointer should be calculated

Return: the pointer from id and offset

function searchId🔗

static id_t searchId(
    ptr_t ptr
)

get the id for a given ptr

Parameters:

  • ptr the pointer whose corresponding id is searched for

Return: id the pointer was registered to

function isValid🔗

static bool isValid(
    id_t id
)

checks if given id is valid

Parameters:

  • id is the id to be checked

Return: true if the given id is valid, otherwise false

function getRepository🔗

static PointerRepository< id_t, ptr_t > & getRepository()

returns the pointer repository

Return: the pointer repository

Public Attributes Documentation🔗

variable NULL_POINTER_ID🔗

static constexpr id_t NULL_POINTER_ID = std::numeric_limits<id_t>::max();

variable NULL_POINTER_OFFSET🔗

static constexpr offset_t NULL_POINTER_OFFSET = std::numeric_limits<offset_t>::max();

Protected Attributes Documentation🔗

variable m_id🔗

id_t m_id {NULL_POINTER_ID};

variable m_offset🔗

offset_t m_offset {NULL_POINTER_OFFSET};

Updated on 31 May 2022 at 15:29:15 CEST