Free Memory Leak Checker (C++)

Started by
13 comments, last by TechnoCore 16 years, 2 months ago
Quote:This intrigues me. At least I've never heard of such technique, most other memory managers need to be included at beginning.

The ones that require including at the beginning will typically use macros and redefine new/malloc, which breaks placement new and member functions that happen to be called free, etc.
The init_seg / __declspec(allocate) technique is useful for performing init before main, before constructors run, or even before the CRT modules are initialized. See http://blogs.msdn.com/larryosterman/archive/2004/09/27/234840.aspx for an explanation.

Incidentally, Steve overrides global operator new, which happens at link-time and requires no init, but the synchronization object and dbghelp do. BTW, another advantage of allocation hooks is that they are called while under the CRT _HEAP_LOCK, which goes a long way towards making a memory manager thread-safe without any further work.

Quote:The problem MindWipe was having turned out to be a genuine memory leak (GLUT never returning, so memory never being deleted), but I thought it was because some global was getting destroyed after the _CrtDumpLeakCheck (Or whatever the function is).

Ah, ok. You can pretty much rely on the CRT report because it has the final word on shutdown order.

Zipster: good idea. 28 MB in spite of this optimization, though? That is an excellent motivation for me to finish up the zero storage scheme :)
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3
Advertisement
Whoa, got some freaky deja vu. Probably from Jan Wassenberg's old post when he announced his manager and discussed some of the same issues.

Because Evil Steve, you haven't mentioned this before?

[Edited by - Boder on February 19, 2008 1:21:49 PM]
Quote:Original post by Boder
Because Evil Steve, you haven't mentioned this before?
I've posted a similar memory manager before, but it was just straight from my engine code and needed tweaking to get it to compile; it was intended as a code sample for something or other, not something people can download and drop into their code like this.
Quote:Original post by Jan Wassenberg
Zipster: good idea. 28 MB in spite of this optimization, though? That is an excellent motivation for me to finish up the zero storage scheme :)

Yes, however I misspoke. It was the allocations we were storing in a hash map, and the stack traces were in a static array. This array was about 21 MB, and the hash map overhead was another 7 MB or so. However we did manage to fill the entire stack trace array on a few occasions, so ~28 MB was indeed in active use at those times.

I should mention that this was the usage we measured using the release CRT. The amount of additional information we stored with each allocation was much less than a debug CRT header, so there really wasn't much more voodoo magic we could do besides shortening the call stack depth or trying a different container. Believe me we could have used a few tricks, because we were running up against hard memory limits on our target platform :)
Quote:Original post by Evil Steve
"Kosher" meaning "normal" or "standard" singleton. A normal singleton constructs itself the first time it's referenced, E.g.:
*** Source Snippet Removed ***Or similarly, with dynamic allocation. In this case, the singleton is created and destroyed explicitly - the key point is that it's not constructed the first time it's used.

Singletons are usually considered a sign of bad design, since they're really just globals in disguise. See Promit's Journal for some relevant links.


Thanks for the clarification... you had me reading for a couple of hours there ;)

//TechnoCore

This topic is closed to new replies.

Advertisement