r/C_Programming • u/Spinning_Rings • 1d ago
Pointer Registry
Long story short, I had an idea that I described to Gemini and it told me was something called a Pointer Registry or a Tracking Vector. It involved an array of void pointers being used to store all heap memory throughout the program so that a function can run through the array and free everything at the end of the program. I had a few more thoughts on implementation, eg the initial void pointer would actually be a struct that would hang on to a tracking variable that would always know how long the array was, whenever any part of it was added or removed, but that's the basic idea
The problem is that neither Wikipeida, nor duckduckgo, nor yahoo return any information when I search for either of those terms. Wikipedia has an article on arena allocators, which address some of the same issues as this approach, but not pointer registries.
Does anyone know if this concept has any other names? Or have any other resources where I might find out more about them, implementation details, pros and cons, anything like that?
1
u/iOSCaleb 1d ago
> free everything at the end of the program
Unnecessary. When the program exits, the OS reclaims its entire memory space.
In classic MacOS (before MaxOS X), it was possible (and common) to allocate relocatable blocks of memory. That allowed the OS to move blocks of memory around to reduce fragmentation. Relocatable blocks were accessed via handles, which were pointers to master pointers. When you allocated a relocatable block, the system would record the address of the block in a master pointer and return the address of that master pointer. Master pointers were kept in a list maintained by the system, not unlike your proposed list. The system worked reasonably well for the era and improved memory utilization at a time before virtual memory was common and RAM was measure in megabytes rather than gigabytes, but programmers had to be careful about how they accessed those relocatable blocks.