It keeps the allocated memory free from fragmentation by compacting the memory when blocks are freed. A program that uses the managed memory module cannot be sure that allocated memory stays in place. Therefore, a level of indirection is used: access to allocated memory must always be done using a special macro.
Files | |
file | mmem.h |
Header file for the managed memory allocator. | |
file | mmem.c |
Implementation of the managed memory allocator. | |
Data Structures | |
struct | mmem |
Defines | |
#define | MMEM_PTR(m) |
Get a pointer to the managed memory. | |
#define | MMEM_SIZE 4096 |
Functions | |
int | mmem_alloc (struct mmem *m, unsigned int size) |
Allocate a managed memory block. | |
void | mmem_free (struct mmem *m) |
Deallocate a managed memory block. | |
void | mmem_init (void) |
Initialize the managed memory module. | |
Variables | |
unsigned int | avail_memory |
|
Get a pointer to the managed memory.
|
|
Allocate a managed memory block.
Definition at line 80 of file mmem.c. References avail_memory, list_add(), MMEM_SIZE, ptr, and size. |
|
Deallocate a managed memory block.
Definition at line 116 of file mmem.c. References avail_memory, list_remove(), MMEM_SIZE, next, NULL, ptr, and size. |
|
Initialize the managed memory module.
Definition at line 149 of file mmem.c. References avail_memory, list_init(), and MMEM_SIZE. |