r/C_Programming • u/Spinning_Rings • Aug 07 '26
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?
View all comments
Show parent comment
3
u/noneedtoprogram Aug 07 '26
More that tracking it to free at the end like you are suggesting is exactly the same as letting the OS clean up at shutdown, and doesn't solve anything about the way that memory leaks are a problem.
Memory lifespan needs to be carefully managed and should be freed as soon as it is finished with. C++ helps handle this with smart pointers and RAII patterns, in C you just have to be careful and use stack allocated resources as much as possible for scoped lifespan objects.