OS  v1.7.5
Documentation
Loading...
Searching...
No Matches
qOS::mem::pool Class Reference

A Memory Pool object. More...

#include <memory.hpp>

Public Member Functions

 pool (void *pArea, const size_t pSize) noexcept
 Initializes a memory pool instance.
 
bool setup (void *pArea, const size_t pSize) noexcept
 Initializes a memory pool instance. This function should be called once before any heap memory request.
 
void free (void *ptr) noexcept
 Deallocates the space previously allocated by mem::pool::alloc(). Deallocation will be performed in the selected memory pool. If ptr is a nullptr pointer, the function does nothing. The behavior is undefined if selected memory pool has not been initialized. The behavior is undefined if the value of ptr does not equal a value returned earlier by mem::pool::alloc(). The behavior is undefined if the memory area referred to by ptr has already been deallocated, that is, mem::pool::free() has already been called with ptr as the argument and no calls to mem::pool::alloc() resulted in a pointer equal to ptr afterwards. The behavior is undefined if after mem::pool::free() returns, an access is made through the pointer ptr.
 
void * alloc (size_t pSize) noexcept
 Allocate a block of memory that is pSize bytes large. If the requested memory can be allocated, a pointer is returned to the beginning of the memory block.
 
size_t getFreeSize (void) const noexcept
 Returns the total amount of heap space that remains unallocated for the memory pool.
 
bool isInitialized (void) const
 Check if the memory pool instance has been initialized.
 
 operator bool () const noexcept
 Check if the memory pool instance has been initialized.
 

Detailed Description

A Memory Pool object.

A memory pool its a special resource that allows memory blocks to be dynamically allocated from a user-designated memory region. Instead of typical pools with fixed-size block allocation, the pools in QuarkTS++ can be of any size, thereby the user is responsible for selecting the appropriate memory pool to allocate data with the same size.

Constructor & Destructor Documentation

◆ pool()

qOS::mem::pool::pool ( void * pArea,
const size_t pSize )
inlinenoexcept

Initializes a memory pool instance.

Parameters
[in]pAreaA pointer to a memory block uint8_t statically allocated to act as Heap of the memory pool. The size of this block should match the pSize argument.
[in]pSizeThe size of the memory block pointed by pArea

Member Function Documentation

◆ alloc()

void * qOS::mem::pool::alloc ( size_t pSize)
noexcept

Allocate a block of memory that is pSize bytes large. If the requested memory can be allocated, a pointer is returned to the beginning of the memory block.

Attention
This method is NOT interrupt-safe.
Parameters
[in]pSizeSize of the memory block in bytes.
Returns
If the request is successful then a pointer to the memory block is returned. If the function failed to allocate the requested block of memory , a nullptr pointer is returned.

◆ free()

void qOS::mem::pool::free ( void * ptr)
noexcept

Deallocates the space previously allocated by mem::pool::alloc(). Deallocation will be performed in the selected memory pool. If ptr is a nullptr pointer, the function does nothing. The behavior is undefined if selected memory pool has not been initialized. The behavior is undefined if the value of ptr does not equal a value returned earlier by mem::pool::alloc(). The behavior is undefined if the memory area referred to by ptr has already been deallocated, that is, mem::pool::free() has already been called with ptr as the argument and no calls to mem::pool::alloc() resulted in a pointer equal to ptr afterwards. The behavior is undefined if after mem::pool::free() returns, an access is made through the pointer ptr.

Attention
This method is NOT interrupt-safe.
Parameters
[in]ptrto the memory to deallocate

◆ getFreeSize()

size_t qOS::mem::pool::getFreeSize ( void ) const
noexcept

Returns the total amount of heap space that remains unallocated for the memory pool.

Returns
The size of the unallocated heap.

◆ isInitialized()

bool qOS::mem::pool::isInitialized ( void ) const
inline

Check if the memory pool instance has been initialized.

Returns
true if instance has been initialized

◆ operator bool()

qOS::mem::pool::operator bool ( ) const
inlineexplicitnoexcept

Check if the memory pool instance has been initialized.

Returns
true if instance has been initialized

◆ setup()

bool qOS::mem::pool::setup ( void * pArea,
const size_t pSize )
noexcept

Initializes a memory pool instance. This function should be called once before any heap memory request.

Parameters
[in]pAreaA pointer to a memory block uint8_t statically allocated to act as Heap of the memory pool. The size of this block should match the pSize argument.
[in]pSizeThe size of the memory block pointed by pArea
Returns
Returns true on success, otherwise, returns false.