Heap subsystem (public interface).
More...
Data Structures |
struct | Heap |
| A heap. More...
|
Defines |
#define | HEAP_DEFINE_BUF(name, size) heap_buf_t name[((size) + sizeof(heap_buf_t) - 1) / sizeof(heap_buf_t)] |
| Utility macro to allocate a heap of size size.
|
Functions |
void | heap_init (struct Heap *heap, void *memory, size_t size) |
| Initialize heap within the buffer pointed by memory which is of size bytes.
|
void * | heap_allocmem (struct Heap *heap, size_t size) |
| Allocate a chunk of memory of size bytes from the heap.
|
void | heap_freemem (struct Heap *heap, 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.
|
Compatibility interface with C standard library |
void * | heap_malloc (struct Heap *heap, size_t size) |
| Standard malloc interface.
|
void * | heap_calloc (struct Heap *heap, size_t size) |
| Standard calloc interface.
|
void | heap_free (struct Heap *heap, void *mem) |
| Free a block of memory, determining its size automatically.
|
Detailed Description
Heap subsystem (public interface).
- Author:
- Bernie Innocenti <bernie@codewiz.org>
Define Documentation
#define HEAP_DEFINE_BUF |
( |
|
name, |
|
|
|
size |
|
) |
| heap_buf_t name[((size) + sizeof(heap_buf_t) - 1) / sizeof(heap_buf_t)] |
Utility macro to allocate a heap of size size.
- Parameters:
-
name | Variable name for the heap. |
size | Heap size in bytes. |
Definition at line 79 of file heap.h.
Function Documentation
void heap_free |
( |
struct Heap * |
h, |
|
|
void * |
mem |
|
) |
| |
Free a block of memory, determining its size automatically.
- Parameters:
-
- 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().
Definition at line 247 of file heap.c.
size_t heap_freeSpace |
( |
struct Heap * |
h | ) |
|
Returns the number of free bytes in a heap.
- Parameters:
-
- 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.
Definition at line 196 of file heap.c.