Class BaseRelativePointer
Defined in File base_relative_pointer.hpp
Inheritance Relationships
Derived Types
public iox::rp::RelativePointer< Index_t >(Template Class RelativePointer)public iox::rp::RelativePointer< T >(Template Class RelativePointer)
Class Documentation
-
class 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.
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.
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).
Subclassed by iox::rp::RelativePointer< Index_t >, iox::rp::RelativePointer< T >
Public Types
-
using id_t = uint64_t
-
using ptr_t = void*
-
using const_ptr_t = const void*const
-
using offset_t = std::uintptr_t
Public Functions
-
BaseRelativePointer(ptr_t ptr, id_t id) noexcept
constructs a BaseRelativePointer pointing to the same pointee as ptr in a segment identified by id
- Parameters:
ptr – [in] the pointer whose pointee shall be the same for this
id – [in] is the unique id of the segment
-
BaseRelativePointer(offset_t offset, id_t id) noexcept
constructs a BaseRelativePointer from a given offset and segment id
- Parameters:
offset – [in] is the offset
id – [in] is the unique id of the segment
-
BaseRelativePointer(ptr_t ptr = nullptr) noexcept
constructs a BaseRelativePointer pointing to the same pointer as ptr
- Parameters:
ptr – [in] the pointer whose pointee shall be the same for this
-
BaseRelativePointer(const BaseRelativePointer &other) noexcept
copy constructor
- Parameters:
other – [in] is the copy origin
-
BaseRelativePointer(BaseRelativePointer &&other) noexcept
move constructor
- Parameters:
other – [in] is the move origin
-
BaseRelativePointer &operator=(const BaseRelativePointer &other) noexcept
copy assignment
- Parameters:
other – [in] is the copy origin
- Returns:
a reference to self
-
BaseRelativePointer &operator=(void *ptr) noexcept
assigns the BaseRelativePointer to point to the same pointee as ptr
- Parameters:
ptr – [in] the pointer whose pointee shall be the same for this
- Returns:
reference to self
-
BaseRelativePointer &operator=(BaseRelativePointer &&other) noexcept
move assignment
- Parameters:
other – [in] is the move origin
- Returns:
a reference to self
-
ptr_t get() const noexcept
access to the underlying object
- Returns:
a pointer to the underlying object
-
id_t getId() const noexcept
returns the id which identifies the segment
- Returns:
the id which identifies the segment
-
ptr_t getBasePtr() const noexcept
get the base pointer associated with this’ id
- Returns:
the registered base pointer
Public Static Functions
-
static id_t registerPtr(const ptr_t ptr, uint64_t size = 0U) noexcept
registers a memory segment at ptr with size of a new id
- Parameters:
ptr – [in] starting address of the segment to be registered
size – [in] is the size of the segment
- Returns:
id it was registered to
-
static bool registerPtr(const id_t id, const ptr_t ptr, uint64_t size = 0U) noexcept
tries to register a memory segment with a given size starting at ptr to a given id
- Parameters:
id – [in] is the id of the segment
ptr – [in] starting address of the segment to be registered
size – [in] is the size of the segment
- Returns:
true if successful (id not occupied), false otherwise
-
static bool unregisterPtr(const id_t id) noexcept
unregisters ptr with given id
- Parameters:
id – [in] is the id of the segment
- Returns:
true if successful (ptr was registered with this id before), false otherwise
-
static ptr_t getBasePtr(const id_t id) noexcept
get the base ptr associated with the given id
- Parameters:
id – [in] is the id of the segment
- Returns:
ptr registered at the given id, nullptr if none was registered
-
static void unregisterAll() noexcept
unregisters all ptr id pairs (leads to initial state)
-
static offset_t getOffset(const id_t id, const_ptr_t ptr) noexcept
get the offset from id and ptr
- Parameters:
id – [in] is the id of the segment and is used to get the base pointer
ptr – [in] is the pointer whose offset should be calculated
- Returns:
offset
-
static ptr_t getPtr(const id_t id, const offset_t offset) noexcept
get the pointer from id and offset (“inverse” to getOffset)
- Parameters:
id – [in] is the id of the segment and is used to get the base pointer
offset – [in] is the offset for which the pointer should be calculated
- Returns:
the pointer from id and offset
-
static id_t searchId(ptr_t ptr) noexcept
get the id for a given ptr
- Parameters:
ptr – [in] the pointer whose corresponding id is searched for
- Returns:
id the pointer was registered to
-
static bool isValid(id_t id) noexcept
checks if given id is valid
- Parameters:
id – [in] is the id to be checked
- Returns:
true if the given id is valid, otherwise false
-
static PointerRepository<id_t, ptr_t> &getRepository() noexcept
returns the pointer repository
- Returns:
the pointer repository
Public Static Attributes
-
using id_t = uint64_t