heap.c File Reference
Heap subsystem (public interface). More...
#include "heap.h"#include "cfg/cfg_heap.h"#include <cfg/compiler.h>#include <cfg/macros.h>#include <cfg/debug.h>#include <string.h>Go to the source code of this file.
Functions | |
| void | heap_init (struct Heap *h, void *memory, size_t size) |
| Initialize heap within the buffer pointed by memory which is of size bytes. | |
| void * | heap_allocmem (struct Heap *h, size_t size) |
| Allocate a chunk of memory of size bytes from the heap. | |
| void | heap_freemem (struct Heap *h, void *mem, size_t size) |
| Free a chunk of memory of size bytes from the heap. | |
| size_t | heap_freeSpace (struct Heap *h) |
| Returns the number of free bytes in a heap. | |
| void | heap_free (struct Heap *h, void *mem) |
| Free a block of memory, determining its size automatically. | |
Detailed Description
Heap subsystem (public interface).
Definition in file heap.c.
Function Documentation
| void heap_free | ( | struct Heap * | h, | |
| void * | mem | |||
| ) |
Free a block of memory, determining its size automatically.
- Parameters:
-
h Heap from which the block was allocated. mem Pointer to a block of memory previously allocated with either heap_malloc() or heap_calloc().
- Note:
- If mem is a NULL pointer, no operation is performed.
- Freeing the same memory block twice has undefined behavior.
- This function works like the ANSI C free().
| size_t heap_freeSpace | ( | struct Heap * | h | ) |
Returns the number of free bytes in a heap.
- Parameters:
-
h the heap to check.
- Note:
- The returned value is the sum of all free memory regions in the heap. Those regions are likely to be *not* contiguous, so a successive allocation may fail even if the requested amount of memory is lower than the current free space.
