iox::roudi::MemoryProvider🔗
This class creates memory which is requested by the MemoryBlocks. Once the memory is available, this is announced to the blocks, so that they can consume the memory for their needs. When the Memory is release, the blocks will also called to handle this appropriately, e.g. calling the destructor of the underlying type. This class is an interface with some default behavior and needs an implementation for real memory supply, e.g. a PosixShmMemoryProvider.
#include <iceoryx_posh/roudi/memory/memory_provider.hpp>
Inherited by iox::roudi::PosixShmMemoryProvider
Public Functions🔗
Name | |
---|---|
MemoryProvider() =default | |
virtual | ~MemoryProvider() |
MemoryProvider(const MemoryProvider & ) | |
MemoryProvider(MemoryProvider && ) | |
MemoryProvider & | operator=(const MemoryProvider & ) |
MemoryProvider & | operator=(MemoryProvider && ) |
cxx::expected< MemoryProviderError > | addMemoryBlock(cxx::not_null< MemoryBlock * > memoryBlock) This function add a MemoryBlock to the list of memory requester. |
cxx::expected< MemoryProviderError > | create() With this call the memory requested by the MemoryBlocks need to be created. The function should be called from a MemoryManager which handles one or more MemoryProvider. |
void | announceMemoryAvailable() This function announces the availability of the memory to the MemoryBlocks. The function should be called from a MemoryManager which handles one or more MemoryProvider. |
cxx::expected< MemoryProviderError > | destroy() This function destroys the previously allocated memory. Before the destruction, all MemoryBlocks are requested to handle this appropriately, e.g. call the destructor of the underlying type. The function should be called from a MemoryManager which handles one or more MemoryProvider. |
cxx::optional< void * > | baseAddress() const This function provides the base address of the created memory. |
uint64_t | size() const This function provides the size of the created memory. |
cxx::optional< uint64_t > | segmentId() const This function provides the segment id of the relocatable memory segment which is owned by the MemoryProvider. |
bool | isAvailable() const This function can be used to check if the requested memory is already available. |
bool | isAvailableAnnounced() const This function can be used to check if the availability of the memory was announced to the MemoryBlocks. |
Protected Functions🔗
Name | |
---|---|
virtual cxx::expected< void *, MemoryProviderError > | createMemory(const uint64_t size, const uint64_t alignment) =0 This function needs to be implemented to provide the actual memory, e.g. in case of POSIX SHM, shm_open and mmap would need to be called in the implementation of this function. |
virtual cxx::expected< MemoryProviderError > | destroyMemory() =0 This function needs to be implemented to free the actual memory, e.g. in case of POSIX SHM, shm_unlink and munmap would need to be called in the implementation of this function. |
const char * | getErrorString(const MemoryProviderError error) |
Friends🔗
Name | |
---|---|
class | RouDiMemoryManager |
Public Functions Documentation🔗
function MemoryProvider🔗
MemoryProvider() =default
function ~MemoryProvider🔗
virtual ~MemoryProvider()
function MemoryProvider🔗
MemoryProvider(
const MemoryProvider &
)
Note: this is intentional not movable/copyable, since a pointer to the memory provider is registered at the RouDiMemoryManager and therefore an instance of a MemoryProvider must be pinned to memory
function MemoryProvider🔗
MemoryProvider(
MemoryProvider &&
)
function operator=🔗
MemoryProvider & operator=(
const MemoryProvider &
)
function operator=🔗
MemoryProvider & operator=(
MemoryProvider &&
)
function addMemoryBlock🔗
cxx::expected< MemoryProviderError > addMemoryBlock(
cxx::not_null< MemoryBlock * > memoryBlock
)
This function add a MemoryBlock to the list of memory requester.
Parameters:
- memoryBlock is a pointer to a user defined MemoryBlock
Return: an MemoryProviderError::MEMORY_BLOCKS_EXHAUSTED error if no further memory blocks can be added, otherwise success
function create🔗
cxx::expected< MemoryProviderError > create()
With this call the memory requested by the MemoryBlocks need to be created. The function should be called from a MemoryManager which handles one or more MemoryProvider.
Return: an MemoryProviderError if memory allocation was not successful, otherwise success
function announceMemoryAvailable🔗
void announceMemoryAvailable()
This function announces the availability of the memory to the MemoryBlocks. The function should be called from a MemoryManager which handles one or more MemoryProvider.
function destroy🔗
cxx::expected< MemoryProviderError > destroy()
This function destroys the previously allocated memory. Before the destruction, all MemoryBlocks are requested to handle this appropriately, e.g. call the destructor of the underlying type. The function should be called from a MemoryManager which handles one or more MemoryProvider.
Return: an error if memory destruction was not successful, otherwise success
function baseAddress🔗
cxx::optional< void * > baseAddress() const
This function provides the base address of the created memory.
Return: an optional pointer to the base address of the created memory if the memory is available, otherwise a cxx::nullopt_t
function size🔗
uint64_t size() const
This function provides the size of the created memory.
Return: the size of the created memory
function segmentId🔗
cxx::optional< uint64_t > segmentId() const
This function provides the segment id of the relocatable memory segment which is owned by the MemoryProvider.
Return: an optional segment id for the created memory if the memory is available, otherwise cxx::nullopt_t
function isAvailable🔗
bool isAvailable() const
This function can be used to check if the requested memory is already available.
Return: true if the requested memory is available, false otherwise
function isAvailableAnnounced🔗
bool isAvailableAnnounced() const
This function can be used to check if the availability of the memory was announced to the MemoryBlocks.
Return: true if the availability of the memory was announced to the MemoryBlocks, false otherwise
Protected Functions Documentation🔗
function createMemory🔗
virtual cxx::expected< void *, MemoryProviderError > createMemory(
const uint64_t size,
const uint64_t alignment
) =0
This function needs to be implemented to provide the actual memory, e.g. in case of POSIX SHM, shm_open and mmap would need to be called in the implementation of this function.
Parameters:
- size is the size in bytes for the requested memory, the size should already be calculated according to the alignment requirements
- alignment the required alignment for the memory
Return: the pointer of the begin of the created memory or a MemoryProviderError if the memory could not be created
Reimplemented by: iox::roudi::PosixShmMemoryProvider::createMemory
function destroyMemory🔗
virtual cxx::expected< MemoryProviderError > destroyMemory() =0
This function needs to be implemented to free the actual memory, e.g. in case of POSIX SHM, shm_unlink and munmap would need to be called in the implementation of this function.
Return: a MemoryProviderError if the destruction failed, otherwise success
Reimplemented by: iox::roudi::PosixShmMemoryProvider::destroyMemory
function getErrorString🔗
static const char * getErrorString(
const MemoryProviderError error
)
Friends🔗
friend RouDiMemoryManager🔗
friend class RouDiMemoryManager(
RouDiMemoryManager
);
Updated on 31 May 2022 at 11:34:55 CEST