FreeRTOS Addons
|
#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) |
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.
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.
itemSize | How big is each item you want to allocate. |
itemCount | How many items max do you want to allocate at once. |
Alignment | Power of 2 value denoting on which address boundary the memory will be aligned to. Must be at least sizeof(unsigned char *). |
MemoryPoolMallocException | on failure. |
MemoryPoolBadAlignmentException | on failure. |
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.
itemSize | How big is each item you want to allocate. |
preallocatedMemory | Pointer to the preallocated memory you are dedicating to this pool. |
preallocatedMemorySize | How big is the buffer you are passing in. |
Alignment | Power of 2 value denoting on which address boundary the memory will be aligned to. Must be at least sizeof(unsigned char *). |
MemoryPoolBadAlignmentException | on failure. |
void MemoryPool::AddMemory | ( | int | itemCount | ) |
Allows you to add memory to a MemoryPool.
Items will be the same size as you initially asked for.
itemCount | How many more items max do you want to allocate |
MemoryPoolMallocException | on failure. |
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.
preallocatedMemory | Pointer to the preallocated memory you are dedicating to this pool. |
preallocatedMemorySize | How big is the buffer you are passing in. |
void * MemoryPool::Allocate | ( | ) |
Allocate an item from the pool.
void MemoryPool::Free | ( | void * | item | ) |
Returns the item back to it's pool.