pico]OS  1.0.4
Functions
Memory Management
User API: Nano Layer

Functions

NANOEXT void *POSCALL nosMemAlloc (UINT_t size)
NANOEXT void POSCALL nosMemFree (void *p)
NANOEXT void POSCALL * nosMemRealloc (void *memblock, UINT_t size)
NANOEXT void POSCALL nosMemSet (void *buf, char val, UINT_t count)
NANOEXT void POSCALL nosMemCopy (void *dst, void *src, UINT_t count)

Detailed Description

Note: This API is part of the nano layer

The nano layer supplies a set of memory management functions. pico]OS functions are thread save, thus pico]OS can replace the memory allocation functions of a runtime library that was not designed for a multitasking environment.


Function Documentation

NANOEXT void* POSCALL nosMemAlloc ( UINT_t  size)

Allocate memory from the heap. This function allocates a block of memory from the heap. The function is thread save, thus multiple threads can access the heap without corrupting it.

Parameters:
sizein bytes of the memory block to allocate.
Returns:
The function returns the pointer to the new memory block on success. NULL is returned when the function failed to allocate a block with the wished size.
Note:
NOSCFG_FEATURE_MEMALLOC must be defined to 1 to have this function compiled in.
See also:
nosMemRealloc, nosMemFree, NOSCFG_MEM_MANAGER_TYPE
NANOEXT void POSCALL nosMemCopy ( void *  dst,
void *  src,
UINT_t  count 
)

Copy a block of memory. This function works like the memcpy function from the C runtime library.

Parameters:
dstpointer to the destination memory block
srcpointer to the source memory block
countnumber of bytes to copy
Note:
NOSCFG_FEATURE_MEMCOPY must be defined to 1 to have this function compiled in.
See also:
nosMemAlloc, nosMemSet
NANOEXT void POSCALL nosMemFree ( void *  p)

Free a block of memory to the heap. This function is the counterpart to nosMemAlloc.

Parameters:
ppointer to the memory block to free.
Note:
NOSCFG_FEATURE_MEMALLOC must be defined to 1 to have this function compiled in.
See also:
nosMemAlloc, nosMemRealloc, NOSCFG_MEM_MANAGER_TYPE
NANOEXT void POSCALL* nosMemRealloc ( void *  memblock,
UINT_t  size 
)

Reallocate a block of memory. Sometimes it is necessary to increase or decrease the size of a memory block on the heap. This function works like the usual realloc(), it is optimized to keep the heap clean and unfragmented.

Parameters:
memblockpointer to the memory block on the heap.
sizenew size of the memory block (larger or smaller)
Returns:
The function returns the pointer to the new memory block on success. NULL is returned when the function failed to change the size of the block.
Note:
NOSCFG_FEATURE_MEMALLOC and NOSCFG_FEATURE_REALLOC must be defined to 1 to have this function compiled in.
nosMemRealloc reaches the best performance only when NOSCFG_MEM_MANAGE_MODE is set to 1
See also:
nosMemAlloc, nosMemFree, NOSCFG_MEM_MANAGER_TYPE
NANOEXT void POSCALL nosMemSet ( void *  buf,
char  val,
UINT_t  count 
)

Fill a block of memory with a special character. This function works like the memset function from the C runtime library.

Parameters:
bufpointer to the destination memory block
valcharacter to fill into the memory block
countnumber of bytes to fill into the block
Note:
NOSCFG_FEATURE_MEMSET must be defined to 1 to have this function compiled in.
See also:
nosMemAlloc, nosMemCopy