AWS IoT Device SDK C: Static Memory
Statically-allocated buffer pools
Return to main page ↑
IotStaticMemory_ReturnInUse

Return an "in-use" buffer.

void IotStaticMemory_ReturnInUse( void * ptr,
void * pPool,
uint32_t * pInUse,
size_t limit,
size_t elementSize );

This function is common to the static memory implementation.

Parameters
[in]ptrPointer to the buffer to return.
[in]pPoolThe pool of buffers that the in-use buffer was allocated from.
[in]pInUseThe "in-use" flags for pPool.
[in]limitHow many buffers (and flags) to check while searching for ptr.
[in]elementSizeThe size of a single element in pPool.

Example:

// To use this function, first declare two arrays. One provides the statically-allocated
// objects, the other provides flags to determine which objects are in-use.
#define NUMBER_OF_OBJECTS ...
#define OBJECT_SIZE ...
static uint32_t _pInUseObjects[ NUMBER_OF_OBJECTS ] = { 0 };
static uint8_t _pObjects[ NUMBER_OF_OBJECTS ][ OBJECT_SIZE ] = { { 0 } }; // Placeholder for objects.
// The function to free statically-allocated objects. Must have the same signature
// as free().
void Iot_FreeObject( void * ptr )
{
_pObjects,
_pInUseObjects,
NUMBER_OF_OBJECTS,
OBJECT_SIZE );
}