- Main Page
- Modules
- Data Structures
- Files

# Memory Management
[User API: Nano Layer]

## Functions
NANOEXT void * | nosMemAlloc (UINT_t size)
NANOEXT void | nosMemFree (void *p)
NANOEXT void * | nosMemRealloc (void *memblock, UINT_t size)
NANOEXT void | nosMemSet (void *buf, char val, UINT_t count)
NANOEXT void | 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* 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:
  | size | in 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 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:
  | dst | pointer to the destination memory block
  | src | pointer to the source memory block
  | count | number 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 nosMemFree | ( | void * | p | ) |

  | Free a block of memory to the heap. This function is the counterpart to nosMemAlloc. Parameters:
  | p | pointer 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* 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:
  | memblock | pointer to the memory block on the heap.
  | size | new 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 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:
  | buf | pointer to the destination memory block
  | val | character to fill into the memory block
  | count | number 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