iceoryx_posh 2.0.3
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Friends | List of all members
iox::roudi::MemoryProvider Class Referenceabstract

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. More...

#include <iceoryx_posh/roudi/memory/memory_provider.hpp>

Inheritance diagram for iox::roudi::MemoryProvider:
Inheritance graph
[legend]

Public Member Functions

 MemoryProvider (const MemoryProvider &)=delete
 
 MemoryProvider (MemoryProvider &&)=delete
 
MemoryProvideroperator= (const MemoryProvider &)=delete
 
MemoryProvideroperator= (MemoryProvider &&)=delete
 
cxx::expected< MemoryProviderErroraddMemoryBlock (cxx::not_null< MemoryBlock * > memoryBlock) noexcept
 This function add a MemoryBlock to the list of memory requester. More...
 
cxx::expected< MemoryProviderErrorcreate () noexcept
 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. More...
 
void announceMemoryAvailable () noexcept
 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< MemoryProviderErrordestroy () noexcept
 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. More...
 
cxx::optional< void * > baseAddress () const noexcept
 This function provides the base address of the created memory. More...
 
uint64_t size () const noexcept
 This function provides the size of the created memory. More...
 
cxx::optional< uint64_t > segmentId () const noexcept
 This function provides the segment id of the relocatable memory segment which is owned by the MemoryProvider. More...
 
bool isAvailable () const noexcept
 This function can be used to check if the requested memory is already available. More...
 
bool isAvailableAnnounced () const noexcept
 This function can be used to check if the availability of the memory was announced to the MemoryBlocks. More...
 

Protected Member Functions

virtual cxx::expected< void *, MemoryProviderErrorcreateMemory (const uint64_t size, const uint64_t alignment) noexcept=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. More...
 
virtual cxx::expected< MemoryProviderErrordestroyMemory () noexcept=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. More...
 

Static Protected Member Functions

static const char * getErrorString (const MemoryProviderError error) noexcept
 

Friends

class RouDiMemoryManager
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ MemoryProvider()

iox::roudi::MemoryProvider::MemoryProvider ( const MemoryProvider )
delete
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

Member Function Documentation

◆ addMemoryBlock()

cxx::expected< MemoryProviderError > iox::roudi::MemoryProvider::addMemoryBlock ( cxx::not_null< MemoryBlock * >  memoryBlock)
noexcept

This function add a MemoryBlock to the list of memory requester.

Parameters
[in]memoryBlockis a pointer to a user defined MemoryBlock
Returns
an MemoryProviderError::MEMORY_BLOCKS_EXHAUSTED error if no further memory blocks can be added, otherwise success

◆ baseAddress()

cxx::optional< void * > iox::roudi::MemoryProvider::baseAddress ( ) const
noexcept

This function provides the base address of the created memory.

Returns
an optional pointer to the base address of the created memory if the memory is available, otherwise a cxx::nullopt_t

◆ create()

cxx::expected< MemoryProviderError > iox::roudi::MemoryProvider::create ( )
noexcept

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.

Returns
an MemoryProviderError if memory allocation was not successful, otherwise success

◆ createMemory()

virtual cxx::expected< void *, MemoryProviderError > iox::roudi::MemoryProvider::createMemory ( const uint64_t  size,
const uint64_t  alignment 
)
protectedpure virtualnoexcept

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
[in]sizeis the size in bytes for the requested memory, the size should already be calculated according to the alignment requirements
[in]alignmentthe required alignment for the memory
Returns
the pointer of the begin of the created memory or a MemoryProviderError if the memory could not be created

Implemented in iox::roudi::PosixShmMemoryProvider.

◆ destroy()

cxx::expected< MemoryProviderError > iox::roudi::MemoryProvider::destroy ( )
noexcept

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.

Returns
an error if memory destruction was not successful, otherwise success

◆ destroyMemory()

virtual cxx::expected< MemoryProviderError > iox::roudi::MemoryProvider::destroyMemory ( )
protectedpure virtualnoexcept

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.

Returns
a MemoryProviderError if the destruction failed, otherwise success

Implemented in iox::roudi::PosixShmMemoryProvider.

◆ isAvailable()

bool iox::roudi::MemoryProvider::isAvailable ( ) const
noexcept

This function can be used to check if the requested memory is already available.

Returns
true if the requested memory is available, false otherwise

◆ isAvailableAnnounced()

bool iox::roudi::MemoryProvider::isAvailableAnnounced ( ) const
noexcept

This function can be used to check if the availability of the memory was announced to the MemoryBlocks.

Returns
true if the availability of the memory was announced to the MemoryBlocks, false otherwise

◆ segmentId()

cxx::optional< uint64_t > iox::roudi::MemoryProvider::segmentId ( ) const
noexcept

This function provides the segment id of the relocatable memory segment which is owned by the MemoryProvider.

Returns
an optional segment id for the created memory if the memory is available, otherwise cxx::nullopt_t

◆ size()

uint64_t iox::roudi::MemoryProvider::size ( ) const
noexcept

This function provides the size of the created memory.

Returns
the size of the created memory

The documentation for this class was generated from the following file: