1.4.4.13 OSAL_Malloc Function

C

void* OSAL_Malloc(size_t size)

Summary

Allocates memory using the OSAL default allocator.

Description

This function allocates a block of memory from the default allocator from the underlying RTOS. If no RTOS is present, it defaults to malloc. Many operating systems incorporate their own memory allocation scheme, using pools, blocks or by wrapping the standard C library functions in a critical section. Since a MPLAB Harmony application may not know what target OS is being used (if any), this function ensures that the correct thread-safe memory allocator will be used.

Precondition

None.

Parameters

ParamDescription
sizeSize of the requested memory block in bytes

Returns

Pointer to the block of allocated memory. NULL is returned if memory could not be allocated.

Example

// create a working array
uint8_t* pData;

pData = OSAL_Malloc(32);
if (pData != NULL)
{
    ...
}

Remarks

None.