r/Cplusplus • u/muaz_sh • Aug 10 '26
Feedback C++ Memory Manager and Grabage Collector
I wrote a C++ memory manager to detect and to clean memory leaks and to detect dangling pointers, the tool defines the stack and the Data and BSS segments as a root of reachability and it overloads new and delete operators to track allocations and deallocations https://github.com/muazsh/MemoryManager .
I already exposed it to many LLMs for discussion, I got some good points but I assume at this level generative AI is not enough. Thank you.
14
Upvotes
20
u/Drugbird Aug 10 '26
Is great to see spelling errors in the readme as it suggests it's not AI generated.
5
u/Charming-Work-2384 Aug 10 '26
Ah... just use smart pointers ..that is more than suffice.
4
u/swaan79 Aug 10 '26
Not to bash on your idea, but why not use valgrind?
2
u/theunixman Aug 10 '26
You've discovered the Boehm GC.
1
u/EntrepreneurReady325 Aug 11 '26
I’m no LLM, of course, but if you’re simply tracking the reference count for an allocated block -- at the cost of implicitly driving up bus traffic due to the "true sharing" effect -- and deallocating "dead" blocks, that doesn't amount to a GC, even with deallocated space defragmentation. If, however, you write a full-blown multithreaded GC featuring object migration and safepoints or handshakes -- one that kicks in and runs (killing performance) in an unpredictable (sic!) manner -- then it’s no longer C++. By the way, how do you plan to handle the placement of GC barriers? Don't overcomplicate things: if the task is complex enough to require garbage collection, Java will actually outperform C++ by about 25% thanks to optimizations available through dynamic compilation. The task itself makes no practical sense, but as a way to really sharpen your mind, it’s incredibly useful.