# KE_MEM
[KERNEL]

Heap management module. More...

Collaboration diagram for KE_MEM:

## Data Structures
struct | mblock_free
| Free memory block delimiter structure (size must be word multiple). More...
struct | mblock_used
| Used memory block delimiter structure (size must be word multiple). More...
## Defines
#define | KE_HEAP_SIZE NX_HEAP_SIZE
| Heap size for nX.
## Functions
struct mblock_free * | ke_mem_init (void)
| Heap initialization.
void * | ke_malloc (uint32_t size)
| Allocation of a block of memory.
void | ke_free (void *mem_ptr)
| Freeing of a block of memory.
## Variables
uint8_t | ke_mem_heap [KE_HEAP_SIZE]
| Data area reserved for the kernel heap.

## Detailed Description

Heap management module.

The KEMEM module implements heap management functions that allow initializing heap, allocating and freeing memory.

## Function Documentation

void ke_free | ( | void * | mem_ptr | ) |

Freeing of a block of memory.

Free the memory area pointed by mem_ptr : mark the block as free and insert it in the pool of free block.

Parameters:

  `[in]` | mem_ptr | Pointer to the memory area that need to be freed.

void * ke_malloc | ( | uint32_t | size | ) |

Allocation of a block of memory.

Allocates a memory block whose size is size; if no memory is available return NULL

Parameters:

  `[in]` | size | Size of the memory area that need to be allocated.

Returns:
  A pointer to the allocated memory area.

Referenced by ipc_emb_kmsg_hdlr().

struct mblock_free * ke_mem_init | ( | void |  | ) | `[read]`

Heap initialization.

This function performs the following operations:

- sanity checks
- check memory allocated is at least large enough to hold two block descriptors to hold start and end
- initialize the first and last descriptors
- save the pointer to the first free descriptor

Returns:
  The pointer to the first free block.