NeuroTIC 0.0
Loading...
Searching...
No Matches
ntmemory.h File Reference

Memory Management Functions
http://tituxdev.github.io/NeuroTIC/src/CPU/ntmemory.c. More...

This graph shows which files directly or indirectly include this file:

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.
 

Detailed Description

Memory Management Functions
http://tituxdev.github.io/NeuroTIC/src/CPU/ntmemory.c.

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.

Author
Oscar Sotomayor.
Date
2026

Definition in file ntmemory.h.

Function Documentation

◆ memfree()

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().

◆ memtrack()

void * memtrack ( void *  mem)

Registers a memory block for tracking and automatic cleanup.

Parameters
memPointer to the memory block to track.

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().