CppELib 1.7.0
Loading...
Searching...
No Matches
OSWrapper::FixedMemoryPool Class Referenceabstract

Abstract class that has functions of common RTOS's fixed-size memory pool. More...

#include <FixedMemoryPool.h>

Public Member Functions

virtual void * allocate ()=0
 Allocate a block from this FixedMemoryPool.
 
virtual void deallocate (void *p)=0
 Release the allocated block.
 
virtual std::size_t getBlockSize () const =0
 Get the block size.
 
virtual Error allocateMemory (void **memory)
 Block the current thread until a memory block is allocated from this FixedMemoryPool.
 
virtual Error tryAllocateMemory (void **memory)
 Try to allocate a memory block from this FixedMemoryPool without blocking.
 
virtual Error timedAllocateMemory (void **memory, Timeout tmout)
 Block the current thread until a memory block is allocated from this FixedMemoryPool but only within the limited time.
 
virtual std::size_t getNumberOfAvailableBlocks () const
 Get the remaining number of available blocks in this FixedMemoryPool.
 
virtual std::size_t getMaxNumberOfBlocks () const
 Get the max number of blocks in this FixedMemoryPool.
 

Static Public Member Functions

static FixedMemoryPoolcreate (std::size_t blockSize, std::size_t memoryPoolSize, void *memoryPoolAddress=0)
 Create a FixedMemoryPool object.
 
static void destroy (FixedMemoryPool *p)
 Destroy a FixedMemoryPool object.
 
static std::size_t getRequiredMemorySize (std::size_t blockSize, std::size_t numBlocks)
 Get the required total memory size for allocation of (blockSize * numBlocks)
 

Protected Member Functions

virtual ~FixedMemoryPool ()
 

Detailed Description

Abstract class that has functions of common RTOS's fixed-size memory pool.

Constructor & Destructor Documentation

◆ ~FixedMemoryPool()

virtual OSWrapper::FixedMemoryPool::~FixedMemoryPool ( )
inlineprotectedvirtual

Member Function Documentation

◆ allocate()

virtual void * OSWrapper::FixedMemoryPool::allocate ( )
pure virtual

Allocate a block from this FixedMemoryPool.

Returns
If free blocks exist in the memory pool then returns a pointer of allocated block, else returns null pointer

Implemented in StdCppOSWrapper::StdCppFixedMemoryPool, and TestDoubleOSWrapper::TestDoubleFixedMemoryPool.

◆ allocateMemory()

Error OSWrapper::FixedMemoryPool::allocateMemory ( void **  memory)
virtual

Block the current thread until a memory block is allocated from this FixedMemoryPool.

Parameters
[out]memoryPointer of pointer that stores the allocated memory
Return values
OKSuccess. A memory is allocated
InvalidParameterParameter memory is null pointer
CalledByNonThreadCalled from non thread context (interrupt handler, timer, etc)
OtherErrorNot implemented in concrete class
Note
Call deallocate() to release a memory block allocated by this method
Same as timedAllocateMemory(memory, Timeout::FOREVER)

Reimplemented in StdCppOSWrapper::StdCppFixedMemoryPool.

◆ create()

FixedMemoryPool * OSWrapper::FixedMemoryPool::create ( std::size_t  blockSize,
std::size_t  memoryPoolSize,
void *  memoryPoolAddress = 0 
)
static

Create a FixedMemoryPool object.

Parameters
blockSizeNumber of bytes of one fixed-size memory block
memoryPoolSizeNumber of bytes of memory pool
memoryPoolAddressMemory pool address
Returns
If this method succeeds then returns a pointer of FixedMemoryPool object, else returns null pointer
Note
If memoryPoolAddress is null pointer, using memory pool area that RTOS prepared.

◆ deallocate()

virtual void OSWrapper::FixedMemoryPool::deallocate ( void *  p)
pure virtual

Release the allocated block.

Parameters
pPointer of allocated block
Note
If p is null pointer, do nothing.

Implemented in StdCppOSWrapper::StdCppFixedMemoryPool, and TestDoubleOSWrapper::TestDoubleFixedMemoryPool.

◆ destroy()

void OSWrapper::FixedMemoryPool::destroy ( FixedMemoryPool p)
static

Destroy a FixedMemoryPool object.

Parameters
pPointer of FixedMemoryPool object created by FixedMemoryPool::create()
Note
If p is null pointer, do nothing.

◆ getBlockSize()

virtual std::size_t OSWrapper::FixedMemoryPool::getBlockSize ( ) const
pure virtual

Get the block size.

Returns
Number of bytes of one fixed-size memory block

Implemented in StdCppOSWrapper::StdCppFixedMemoryPool, and TestDoubleOSWrapper::TestDoubleFixedMemoryPool.

◆ getMaxNumberOfBlocks()

std::size_t OSWrapper::FixedMemoryPool::getMaxNumberOfBlocks ( ) const
virtual

Get the max number of blocks in this FixedMemoryPool.

Returns
Max number of blocks
Note
If the concrete class does not implement this method, this method returns 0

Reimplemented in StdCppOSWrapper::StdCppFixedMemoryPool.

◆ getNumberOfAvailableBlocks()

std::size_t OSWrapper::FixedMemoryPool::getNumberOfAvailableBlocks ( ) const
virtual

Get the remaining number of available blocks in this FixedMemoryPool.

Returns
Remaining number of available blocks
Note
If the concrete class does not implement this method, this method returns 0

Reimplemented in StdCppOSWrapper::StdCppFixedMemoryPool.

◆ getRequiredMemorySize()

std::size_t OSWrapper::FixedMemoryPool::getRequiredMemorySize ( std::size_t  blockSize,
std::size_t  numBlocks 
)
static

Get the required total memory size for allocation of (blockSize * numBlocks)

Parameters
blockSizeNumber of bytes of one fixed-size memory block
numBlocksNumber of blocks
Returns
Required total memory size
Note
Return value does not always equal to (blockSize * numBlocks).

◆ timedAllocateMemory()

Error OSWrapper::FixedMemoryPool::timedAllocateMemory ( void **  memory,
Timeout  tmout 
)
virtual

Block the current thread until a memory block is allocated from this FixedMemoryPool but only within the limited time.

Parameters
[out]memoryPointer of pointer that stores the allocated memory
tmoutThe limited time
Return values
OKSuccess. A memory is allocated
TimedOutThe limited time was elapsed
InvalidParameterParameter memory is null pointer
CalledByNonThreadCalled from non thread context (interrupt handler, timer, etc)
OtherErrorNot implemented in concrete class
Note
Call deallocate() to release a memory block allocated by this method
If tmout is Timeout::POLLING then this method tries to allocate a memory block without blocking.
If tmout is Timeout::FOREVER then this method waits forever until a memory block is allocated.

Reimplemented in StdCppOSWrapper::StdCppFixedMemoryPool.

◆ tryAllocateMemory()

Error OSWrapper::FixedMemoryPool::tryAllocateMemory ( void **  memory)
virtual

Try to allocate a memory block from this FixedMemoryPool without blocking.

Parameters
[out]memoryPointer of pointer that stores the allocated memory
Return values
OKSuccess. A memory is allocated
TimedOutFailed. No memory blocks available
InvalidParameterParameter memory is null pointer
OtherErrorNot implemented in concrete class
Note
Call deallocate() to release a memory block allocated by this method
Same as timedAllocateMemory(memory, Timeout::POLLING)

Reimplemented in StdCppOSWrapper::StdCppFixedMemoryPool.


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