FreeRTOS Addons
Loading...
Searching...
No Matches
Public Member Functions | List of all members
cpp_freertos::MemoryPool Class Reference

#include <mem_pool.hpp>

Public Member Functions

 MemoryPool (int itemSize, int itemCount, int alignment)
 
 MemoryPool (int itemSize, void *preallocatedMemory, int preallocatedMemorySize, int alignment)
 
void AddMemory (int itemCount)
 
void AddMemory (void *preallocatedMemory, int preallocatedMemorySize)
 
void * Allocate ()
 
void Free (void *item)
 

Detailed Description

Memory Pools are fixed size allocations to prevent fragmentation.

This is a new feature to FreeRTOS Wrappers and is not in and of itself a wrapper.

Memory Pools are thread safe, but cannot be used in ISR context. The OS must be running, because these use Mutexes to protect internal data structures.

Constructor & Destructor Documentation

◆ MemoryPool() [1/2]

MemoryPool::MemoryPool ( int  itemSize,
int  itemCount,
int  alignment 
)

Constructor to create a Memory Pool.

This constructor uses the system malloc to actually obtain the memory.

Parameters
itemSizeHow big is each item you want to allocate.
itemCountHow many items max do you want to allocate at once.
AlignmentPower of 2 value denoting on which address boundary the memory will be aligned to. Must be at least sizeof(unsigned char *).
Exceptions
MemoryPoolMallocExceptionon failure.
MemoryPoolBadAlignmentExceptionon failure.

◆ MemoryPool() [2/2]

MemoryPool::MemoryPool ( int  itemSize,
void *  preallocatedMemory,
int  preallocatedMemorySize,
int  alignment 
)

Constructor to create a Memory Pool.

This constructor uses memory you pass in to actually create the pool. This constructor does not throw.

Parameters
itemSizeHow big is each item you want to allocate.
preallocatedMemoryPointer to the preallocated memory you are dedicating to this pool.
preallocatedMemorySizeHow big is the buffer you are passing in.
AlignmentPower of 2 value denoting on which address boundary the memory will be aligned to. Must be at least sizeof(unsigned char *).
Exceptions
MemoryPoolBadAlignmentExceptionon failure.

Member Function Documentation

◆ AddMemory() [1/2]

void MemoryPool::AddMemory ( int  itemCount)

Allows you to add memory to a MemoryPool.

Items will be the same size as you initially asked for.

Parameters
itemCountHow many more items max do you want to allocate
Exceptions
MemoryPoolMallocExceptionon failure.

◆ AddMemory() [2/2]

void MemoryPool::AddMemory ( void *  preallocatedMemory,
int  preallocatedMemorySize 
)

Allows you to add memory to a MemoryPool.

Items will be the same size as you initially asked for.

Parameters
preallocatedMemoryPointer to the preallocated memory you are dedicating to this pool.
preallocatedMemorySizeHow big is the buffer you are passing in.

◆ Allocate()

void * MemoryPool::Allocate ( )

Allocate an item from the pool.

Returns
Pointer of the memory or NULL if the pool is empty.

◆ Free()

void MemoryPool::Free ( void *  item)

Returns the item back to it's pool.

Note
There is no checking that the item is actually valid to be returned to this pool.

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