Memory Buffer#

Ember Connect API dynamically allocates and frees memory.

Generally, dynamic memory allocation in embedded code is not recommended. However, in some cases, the drawbacks of avoiding them is even bigger. Using C standard library dynamic memory is still not recommended due because it could cause fragmented memory.

For these reasons, Connect allocates some (configurable in the stack common plugin) memory as HEAP at compile-time. Memory allocation from this heap is possible through the API below.

See memory-buffer.h for source code.

Handlers#

The Application Framework implements all handlers, directly calling their associated callbacks. By default, Connect projects declare such callbacks as stubs in flex-callbacks-stubs.c. Hence, to use an enabled Connect feature, applications should replace the stub with their own implementation of the associated callback (typically in flex-callbacks.c). See UG235.04 for more info.

void

This handler is invoked by the memory buffers system garbage collector and allows the application to properly mark the application-defined EmberBuffer variables with emberMarkBuffer().

APIs#

emberAllocateBuffer(uint16_t dataSizeInBytes)

Dynamically allocates memory.

void
emberMarkBuffer(EmberBuffer *buffer)

Prevent the garbage collector from reclaiming the memory associated with the passed EmberBuffer. The application should call this API within the emberMarkApplicationBuffersHandler() stack handler for each EmberBuffer object.

uint8_t *
emberGetBufferPointer(EmberBuffer buffer)

Return a pointer to the memory segment corresponding to the passed EmberBuffer buffer. Notice that the garbage collector can move memory segments to defragment the available memory. As result, the application should always use this API to obtain an updated pointer prior to accessing the memory.

uint16_t
emberGetBufferLength(EmberBuffer buffer)

Return the length in bytes of the passed EmberBuffer buffer.

uint16_t

Return the available memory at the buffer manager in bytes.

Macros#

#define

A special EmberBuffer ID indicating that no memory is currently allocated.

Handlers Documentation#

emberMarkApplicationBuffersHandler#

void emberMarkApplicationBuffersHandler (void )

This handler is invoked by the memory buffers system garbage collector and allows the application to properly mark the application-defined EmberBuffer variables with emberMarkBuffer().

Parameters
N/A

Warnings


Definition at line 72 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/protocol/flex/stack/include/memory-buffer.h

APIs Documentation#

emberAllocateBuffer#

EmberBuffer emberAllocateBuffer (uint16_t dataSizeInBytes)

Dynamically allocates memory.

Parameters
[in]dataSizeInBytes

The size in bytes of the memory to be allocated.

Returns

  • An EmberBuffer value of EMBER_NULL_BUFFER if the memory management system could not allocate the requested memory, or any other EmberBuffer value indicating that the requested memory was successfully allocated. The allocated memory can easily be freed by assigning an EmberBuffer variable to EMBER_NULL_BUFFER. The memory will be freed by the garbage collector during the next emberTick() call.


Definition at line 92 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/protocol/flex/stack/include/memory-buffer.h

emberMarkBuffer#

void emberMarkBuffer (EmberBuffer * buffer)

Prevent the garbage collector from reclaiming the memory associated with the passed EmberBuffer. The application should call this API within the emberMarkApplicationBuffersHandler() stack handler for each EmberBuffer object.

Parameters
[in]buffer

A pointer to the EmberBuffer buffer to be marked.


Definition at line 101 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/protocol/flex/stack/include/memory-buffer.h

emberGetBufferPointer#

uint8_t * emberGetBufferPointer (EmberBuffer buffer)

Return a pointer to the memory segment corresponding to the passed EmberBuffer buffer. Notice that the garbage collector can move memory segments to defragment the available memory. As result, the application should always use this API to obtain an updated pointer prior to accessing the memory.

Parameters
[in]buffer

A pointer to the EmberBuffer buffer for which the corresponding memory pointer should be returned.

Returns


Definition at line 116 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/protocol/flex/stack/include/memory-buffer.h

emberGetBufferLength#

uint16_t emberGetBufferLength (EmberBuffer buffer)

Return the length in bytes of the passed EmberBuffer buffer.

Parameters
[in]buffer

A pointer to the EmberBuffer buffer for which the corresponding length in bytes should be returned.

Returns

  • The length in bytes of a memory segment corresponding to the passed EmberBuffer buffer.


Definition at line 127 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/protocol/flex/stack/include/memory-buffer.h

emberGetAvailableBufferMemory#

uint16_t emberGetAvailableBufferMemory (void )

Return the available memory at the buffer manager in bytes.

Parameters
N/A

Returns

  • The number of available bytes.


Definition at line 134 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/protocol/flex/stack/include/memory-buffer.h

Macro Definition Documentation#

EMBER_NULL_BUFFER#

#define EMBER_NULL_BUFFER
Value:
0x0000u

A special EmberBuffer ID indicating that no memory is currently allocated.


Definition at line 50 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/protocol/flex/stack/include/memory-buffer.h