theCore C++ embedded framework
ecl::pool_base Class Referenceabstract

Base class for memory pool. More...

#include </home/travis/build/forGGe/theCore/lib/allocators/export/ecl/pool.hpp>

Inheritance diagram for ecl::pool_base:

Public Member Functions

template<typename T >
T * aligned_alloc (size_t n)
 Allocates memory suitable for type T, with respect to its aligment. More...
 
template<typename T >
void deallocate (T *p, size_t n)
 Deallocates memory, previously allocated by aligned_alloc. More...
 
virtual ~pool_base ()
 Destroys a pool. More...
 

Protected Member Functions

virtual uint8_t * real_alloc (size_t n, size_t align, size_t obj_sz)=0
 Allocates chunk with respect to given alingment. More...
 
virtual void real_dealloc (uint8_t *p, size_t n, size_t obj_sz)=0
 Deallocates chunk of given address and length. More...
 

Detailed Description

Base class for memory pool.

Provides interfaces for allocation and deallocation of objects of given type. This abstraction helps split handing of type requirement and memory allocations into separate entities.

See also
ecl::pool

Constructor & Destructor Documentation

◆ ~pool_base()

ecl::pool_base::~pool_base ( )
virtual

Destroys a pool.

Member Function Documentation

◆ aligned_alloc()

template<typename T >
T * ecl::pool_base::aligned_alloc ( size_t  n)

Allocates memory suitable for type T, with respect to its aligment.

This method will allocate continuous block of memory that suitable for given type and count of objects of given type. Start address of that block will be aligned with respect to the given type.

Template Parameters
TA type whose object will be placed in the allocated memory.
Parameters
[in]nCount of objects that will be placed in the allocated memory. Behavior is undefined if given count is equal to 0.
Returns
nullptr if there is no space for given type and count in the pool. Valid pointer returned otherwise.
Here is the call graph for this function:

◆ deallocate()

template<typename T >
void ecl::pool_base::deallocate ( T *  p,
size_t  n 
)

Deallocates memory, previously allocated by aligned_alloc.

Precondition
Memory pool with allocated block of given type, starting from given address and with total size that corresponds to amount of objects that where requested in call to aligned_alloc()
Postcondition
Memory pool with deallocated (invalidated) block in given address with given object count and object type.
Template Parameters
TA type whose object was placed in the pool memory. block was originally allocated for other type. Undefined behavior otherwise.
Parameters
[in]pA pointer to a block of previously allocated memory. If given pointer is outside of pool or it points to a block that wasn't allocated by alligned_alloc() then behavior is undefined.
[in]nCount of objects to deallocate. Must match the value previously passed to alligned_alloc(). Undefined behavior otherwise.
Here is the call graph for this function:

◆ real_alloc()

virtual uint8_t* ecl::pool_base::real_alloc ( size_t  n,
size_t  align,
size_t  obj_sz 
)
protectedpure virtual

Allocates chunk with respect to given alingment.

Parameters
[in]nObject count.
[in]alignRequired align.
[in]obj_szSize of single object.
Returns
nullptr if there is no space for given type and count in the pool. Valid pointer returned otherwise.
See also
aligned_alloc()

Implemented in ecl::pool< blk_sz, blk_cnt >, ecl::pool< get_alloc_blk_size(), 256 >, and pool_mock.

◆ real_dealloc()

virtual void ecl::pool_base::real_dealloc ( uint8_t *  p,
size_t  n,
size_t  obj_sz 
)
protectedpure virtual

Deallocates chunk of given address and length.

Length of chunk is determined by multiplication count of objects by object size.

Parameters
[in]pAddress of a chunk. Must be valid address, returned Previously by real_alloc().
[in]nObjects count. Must be the same as passed to real_alloc() when given chunk was allocated.
[in]obj_szSize of single object. Must be the same as passed to real_alloc() when given chunk was allocated.
See also
deallocate()

Implemented in ecl::pool< blk_sz, blk_cnt >, ecl::pool< get_alloc_blk_size(), 256 >, and pool_mock.


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