Class MemoryBlock
Defined in File memory_block.hpp
Inheritance Relationships
Derived Types
public iox::roudi::GenericMemoryBlock< T >(Template Class GenericMemoryBlock)public iox::roudi::MemPoolCollectionMemoryBlock(Class MemPoolCollectionMemoryBlock)public iox::roudi::MemPoolSegmentManagerMemoryBlock(Class MemPoolSegmentManagerMemoryBlock)public iox::roudi::PortPoolMemoryBlock(Class PortPoolMemoryBlock)
Class Documentation
-
class MemoryBlock
The MemoryBlock is a container for general purpose memory. It is used to request some memory from a MemoryProvider, which can be POSIX SHM, the stack or something completely different. To be able to use the container, some functions need to be implemented. For most use cases the GenericMemoryBlock can be used, which is a templated class and implements the most common case.
Subclassed by iox::roudi::GenericMemoryBlock< T >, iox::roudi::MemPoolCollectionMemoryBlock, iox::roudi::MemPoolSegmentManagerMemoryBlock, iox::roudi::PortPoolMemoryBlock
Public Functions
-
MemoryBlock() noexcept = default
-
virtual ~MemoryBlock() noexcept = default
-
MemoryBlock(const MemoryBlock&) = delete
Note
this is intentional not movable/copyable, since a pointer to the memory block is registered at a MemoryProvider and therefore an instance of a MemoryBlock must be pinned to memory
-
MemoryBlock(MemoryBlock&&) = delete
-
MemoryBlock &operator=(const MemoryBlock&) = delete
-
MemoryBlock &operator=(MemoryBlock&&) = delete
-
virtual uint64_t size() const noexcept = 0
This function provides the size of the required memory for the underlying data. It is needed for the MemoryProvider to calculate the total size of memory.
- Returns:
the required memory as multiple of the alignment
-
virtual uint64_t alignment() const noexcept = 0
This function provides the alignment of the memory for the underlying data. This information is needed for the MemoryProvider.
- Returns:
the alignment of the underlying data.
-
cxx::optional<void*> memory() const noexcept
This function provides the pointer to the requested memory.
- Returns:
an optional pointer to a memory block with the requested size and alignment if the memory is available, otherwise a cxx::nullopt_t
Protected Functions
-
virtual void destroy() noexcept = 0
The MemoryProvider calls this either when MemoryProvider::destroy is called or in its destructor.
Note
This function can be called multiple times. Make sure that the implementation can handle this.
-
virtual void onMemoryAvailable(cxx::not_null<void*> memory) noexcept
This function is called once the memory is available and is therefore the earliest possibility to use the memory.
- Parameters:
memory – [in] pointer to a valid memory block, the same one that the memory() member function would return
-
MemoryBlock() noexcept = default