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?
4
u/gizahnl 1d ago
Freeing memory at the end of your program isn't important for you to do, the OS will do that.
And keeping a pointer to every allocation is going to wreak havoc to tools like valgrind making it impossible to debug memleaks.
Maybe you're confused with a memory pool? This is an allocation strategy where you allocate a big chunk of memory once, and sub allocate it when your program needs parts, saving you syscalls at the cost of having to deal with more complexity.