Memory

Basic memory allocation/loading functions. More...

Macros

#define gos_malloc (name, ptr, size)   gos_core_malloc(ptr, size)
Allocate memory on the heap. More...
#define gos_malloc_named (name, size)   gos_core_malloc_named(size)
Allocate memory on the heap. More...

Functions

gos_result_t gos_free (void *ptr)
Free memory allocated by gos_malloc() or gos_malloc_named() More...
void gos_free_linked_list (void *list)
Free the entries allocated in a linked list. More...

Detailed Description

Basic memory allocation/loading functions.

Macro Definition Documentation

gos_malloc

#define gos_malloc ( name,
ptr,
size
) gos_core_malloc(ptr, size)

Allocate memory on the heap.

If the memory is allocated, it is set to zero first. If this call fails, ptr will contain a NULL pointer. Use gos_free() to release the memory allocated by this function.

Note
Use the gos_malloc() macro which enables malloc debugging.
Parameters
[in] name The name of the allocated data, this is only used when using malloc debugging
[out] ptr Pointer to hold address of allocated data
[in] size Size of memory in bytes to allocated
Returns
gos_result_t result of api call
Examples:
demo/secure_element/commands.c , demo/uart_blaster/uart_blaster.c , network/uart_tcp_client/main.c , test/throughput/main.c , utility/buffer_dump/main.c , utility/json_parser/parse_example2.c , utility/json_parser/parse_example9.c , and utility/msgpack/read_write_stream.c .

gos_malloc_named

#define gos_malloc_named ( name,
size
) gos_core_malloc_named(size)

Allocate memory on the heap.

This has the exact same functionality as gos_malloc() except it directly returns the allocated function pointer. If this call fails, the return value is NULL. Use gos_free() to release the memory allocated by this function.

Note
This API enables malloc debugging.
Parameters
[in] name The name of the allocated data, this is only used when using malloc debugging
[in] size Size of memory in bytes to allocated
Returns
Pointer to allocated memory, NULL on failure

Function Documentation

gos_free()

gos_free_linked_list()

void gos_free_linked_list ( void * list )

Free the entries allocated in a linked list.

The entries of the linked list should be of the form:

struct entry
{
struct entry *next;
...
}

i.e. The first element of each entry should point to the next entry in the list. The 'next' element of the last entry should be NULL.

Parameters
[in] list Linked list to de-allocate