|
NeuroTIC 0.0
|
Implementation of memory management functions. More...

Go to the source code of this file.
Functions | |
| void | memfree (void) |
| Frees all memory blocks registered in the internal tracking registry. | |
| void * | memtrack (void *mem) |
| Registers a memory block for tracking and automatic cleanup. | |
Variables | |
| static void ** | mem_register = NULL |
| Internal registry for tracking allocated memory blocks. | |
| static unsigned int | mem_count = 0 |
| Counter for the number of tracked memory blocks. | |
Implementation of memory management functions.
Provides functions for tracking dynamically allocated memory blocks and ensuring they are freed at program termination.
Uses a dynamic registry to store pointers to allocated memory, and registers a cleanup function with atexit() to automatically free all tracked memory when the program exits.
Definition in file ntmemory.c.
| void memfree | ( | void | ) |
Frees all memory blocks registered in the internal tracking registry.
Frees all memory blocks registered in the internal tracking registry.
Iterates through the mem_register array, freeing each pointer and setting it to NULL to prevent dangling references.
After all tracked memory has been freed, the registry itself is freed and set to NULL.
This function is registered with atexit() to ensure that it is called automatically when the program terminates, providing a safety net for memory management and preventing leaks.
References mem_count, and mem_register.
Referenced by memtrack().
| void * memtrack | ( | void * | mem | ) |
Registers a memory block for tracking and automatic cleanup.
Registers a dynamically allocated memory block for deferred release.
Adds a pointer to the internal memory registry. The registry grows dynamically as new allocations are tracked.
This function is intended to be called immediately after successful dynamic allocation (e.g. malloc, calloc, realloc).
On the first invocation, memfree() is automatically registered to execute at program termination via atexit().
References mem_count, mem_register, and memfree().
|
static |
Counter for the number of tracked memory blocks.
This counter keeps track of how many pointers have been registered in the mem_register array.
It is incremented each time memtrack() is called and decremented as memory blocks are freed in memfree().
The counter is used to manage the size of the registry and to ensure that all tracked memory is properly released when memfree() is invoked.
mem_register. Referenced by memfree(), and memtrack().
|
static |
Internal registry for tracking allocated memory blocks.
This dynamic array stores pointers to all memory blocks that have been registered via memtrack().
The registry allows for collective management of memory, enabling the memfree() function to iterate through all tracked pointers and free them at once.
The registry is dynamically resized as new pointers are added, and is freed itself when memfree() is called.
This approach simplifies memory management by centralizing the tracking and cleanup of dynamically allocated memory within the NeuroTIC system.
Referenced by memfree(), and memtrack().