AWS IoT Device SDK C:
Static Memory
Statically-allocated buffer pools
|
Return to main page ↑ |
Implementation of common static memory functions in iot_static_memory.h. More...
#include "iot_config.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "platform/iot_threads.h"
#include "iot_static_memory.h"
#include "iot_atomic.h"
Functions | |
int32_t | IotStaticMemory_FindFree (uint32_t *pInUse, size_t limit) |
Find a free buffer using the "in-use" flags. More... | |
void | IotStaticMemory_ReturnInUse (void *ptr, void *pPool, uint32_t *pInUse, size_t limit, size_t elementSize) |
Return an "in-use" buffer. More... | |
size_t | Iot_MessageBufferSize (void) |
Get the fixed size of a message buffer. More... | |
void * | Iot_MallocMessageBuffer (size_t size) |
Get an empty message buffer. More... | |
void | Iot_FreeMessageBuffer (void *ptr) |
Free an in-use message buffer. More... | |
Variables | |
static uint32_t | _pInUseMessageBuffers [IOT_MESSAGE_BUFFERS] = { 0U } |
Message buffer in-use flags. | |
static char | _pMessageBuffers [IOT_MESSAGE_BUFFERS][IOT_MESSAGE_BUFFER_SIZE] = { { 0 } } |
Message buffers. | |
Implementation of common static memory functions in iot_static_memory.h.
int32_t IotStaticMemory_FindFree | ( | uint32_t * | pInUse, |
size_t | limit | ||
) |
Find a free buffer using the "in-use" flags.
If a free buffer is found, this function marks the buffer in-use. This function is common to the static memory implementation.
[in] | pInUse | The "in-use" flags to search. |
[in] | limit | How many flags to check, i.e. the size of pInUse . |
-1
if no free buffers are available.Example:
void IotStaticMemory_ReturnInUse | ( | void * | ptr, |
void * | pPool, | ||
uint32_t * | pInUse, | ||
size_t | limit, | ||
size_t | elementSize | ||
) |
Return an "in-use" buffer.
This function is common to the static memory implementation.
[in] | ptr | Pointer to the buffer to return. |
[in] | pPool | The pool of buffers that the in-use buffer was allocated from. |
[in] | pInUse | The "in-use" flags for pPool. |
[in] | limit | How many buffers (and flags) to check while searching for ptr. |
[in] | elementSize | The size of a single element in pPool. |
Example:
size_t Iot_MessageBufferSize | ( | void | ) |
Get the fixed size of a message buffer.
The size of the message buffers are known at compile time, but it is a constant that may not be visible to all source files. This function allows other source files to know the size of a message buffer.
void* Iot_MallocMessageBuffer | ( | size_t | size | ) |
Get an empty message buffer.
This function is the analog of malloc for message buffers.
[in] | size | Requested size for a message buffer. |
size
argument is larger than the fixed size of a message buffer or no message buffers are available, NULL
is returned. void Iot_FreeMessageBuffer | ( | void * | ptr | ) |
Free an in-use message buffer.
This function is the analog of free for message buffers.
[in] | ptr | Pointer to the message buffer to free. |