Isle
Loading...
Searching...
No Matches
MxMemoryPool< BS, NB > Class Template Reference

[AI] Fixed-size memory pool template for fast allocation and deallocation. More...

#include <mxmemorypool.h>

Public Member Functions

 MxMemoryPool ()
 [AI] Constructor. More...
 
 ~MxMemoryPool ()
 [AI] Destructor. More...
 
MxResult Allocate ()
 [AI] Allocates the memory pool according to template parameters. More...
 
MxU8Get ()
 [AI] Gets a pointer to the next available block in the memory pool. More...
 
void Release (MxU8 *p_buf)
 [AI] Releases the block at the given pointer back into the pool. More...
 
MxU32 GetPoolSize () const
 [AI] Returns the number of blocks in the pool. More...
 

Detailed Description

template<size_t BS, size_t NB>
class MxMemoryPool< BS, NB >

[AI] Fixed-size memory pool template for fast allocation and deallocation.

[AI] The MxMemoryPool class manages a pool of buffers of a fixed block size and count, providing fast and efficient memory allocation and release. Internally, a bitset keeps track of used/free blocks and returns pointers to available blocks on request.

Template Parameters
BS[AI] Block size, in kilobytes (each allocation is BS*1024 bytes)
NB[AI] Number of blocks in the pool

Definition at line 21 of file mxmemorypool.h.

Constructor & Destructor Documentation

◆ MxMemoryPool()

template<size_t BS, size_t NB>
MxMemoryPool< BS, NB >::MxMemoryPool ( )
inline

[AI] Constructor.

Initializes an empty pool with the specified block size.

[AI] The actual allocation is deferred until Allocate is called.

Definition at line 27 of file mxmemorypool.h.

◆ ~MxMemoryPool()

template<size_t BS, size_t NB>
MxMemoryPool< BS, NB >::~MxMemoryPool ( )
inline

[AI] Destructor.

Destroys the memory pool and releases its memory.

Definition at line 32 of file mxmemorypool.h.

Member Function Documentation

◆ Allocate()

template<size_t BS, size_t NB>
MxResult MxMemoryPool< BS, NB >::Allocate

[AI] Allocates the memory pool according to template parameters.

Returns
SUCCESS if allocation succeeded; FAILURE otherwise. [AI]

[AI] Allocates a contiguous memory block sufficient for NB blocks of BS*1024 bytes each. Panics if called more than once or with zero block size/count.

Definition at line 71 of file mxmemorypool.h.

◆ Get()

template<size_t BS, size_t NB>
MxU8 * MxMemoryPool< BS, NB >::Get

[AI] Gets a pointer to the next available block in the memory pool.

Returns
Pointer to available memory block, or NULL if all are in use. [AI]

[AI] Scans the block reference bitset for a free block, marks it as used and returns pointer to its start.

Definition at line 84 of file mxmemorypool.h.

◆ GetPoolSize()

template<size_t BS, size_t NB>
MxU32 MxMemoryPool< BS, NB >::GetPoolSize ( ) const
inline

[AI] Returns the number of blocks in the pool.

Returns
Number of blocks managed by the pool (usually NB). [AI]

[AI] Returns the size reported by the MxBitset managing block references.

Definition at line 62 of file mxmemorypool.h.

◆ Release()

template<size_t BS, size_t NB>
void MxMemoryPool< BS, NB >::Release ( MxU8 p_buf)

[AI] Releases the block at the given pointer back into the pool.

Parameters
p_bufPointer within the memory pool to be released. [AI]

[AI] Calculates the block index from the pointer, marks it as free in the block reference bitset.

Definition at line 104 of file mxmemorypool.h.


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