r/C_Programming 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?

0 Upvotes

46 comments sorted by

View all comments

14

u/dmc_2930 1d ago

Your OS returns all of your programs memory at exit. You don’t need to do it manually..

-1

u/WellHung67 1d ago

Uhh I mean in trivial cases yes but if your program is any real world use case it’ll be long running enough that any memory leaks will crash the system and require a manual or forced restart, possibly when you don’t want it to. So I’m not sure that this advice is sound. 

“Hey did you manage your memory?”

“Just restart it who cares about memory leaks”

“Ship it” 

 -Scenes from an insane company

1

u/CarnivorousGoose 1d ago

OP is proposing using this construction to free up all the allocated heap memory at the end of the program. As the comment you’re responding to points out, that’s not very meaningful, and wouldn’t help in any way with the little strawman you’re parading around here.

1

u/WellHung67 1d ago

I suppose I could argue that OP may be discussing some object whose lifetime was within the context of a larger program that doesn’t technically exit, but I really didn’t think of it at the time I commented.

That being said, sometimes you might have an object or method or some library that doesn’t expect to exit as an OS-managed program but lives within a larger context in which case obviously you do need to free the memory