TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Flexible C memory allocation scheme with leak checking

52 pointsby mulle_natover 8 years ago

4 comments

ktRolsterover 8 years ago
1) The documentation doesn&#x27;t show what file needs to be included; I think it&#x27;s &quot;mulle_allocator&#x2F;mulle_allocator.h&quot;<p>2) It can be convenient, in mulle_allocator.h, to have a define: #define malloc() mulle_malloc(). That way you don&#x27;t actually need to dig through the code and replace anything.<p>3) If you&#x27;re doing #defines, you can do something like this: #define malloc(a) mulle_malloc(a, __LINE__, __FILE__) which will let you keep track of the line and file where the memory was allocated.<p>4) If you&#x27;re on Linux (which often C programmers are not) then mtrace() works really nicely for this.<p>5) It&#x27;s always better to have more options for memory debugging, so good job!
评论 #12713850 未加载
JoachimSchipperover 8 years ago
This seems to be a malloc()&#x2F;free() wrapper that keeps track of malloc()ed&#x2F;realloc()ed&#x2F;free()d pointers. I see that it&#x27;s been submitted by the author, so one hopefully-helpful comment: it would be really helpful to highlight why one would use this instead of one of the well-established alternatives (Boehm GC, valgrind, ASan).<p>The &quot;run after every test case&quot; example actually gives a fairly good reason, but note that realistic code bases probably have a few caches, freelist-optimizations or other exceptions to &quot;deallocate all memory after every test&quot;.
评论 #12709405 未加载
评论 #12713484 未加载
zdeover 8 years ago
How do you redirect strdup() et al to your malloc? What&#x27;s wrong with malloc hooks?<p><a href="http:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;libc&#x2F;manual&#x2F;html_node&#x2F;Hooks-for-Malloc.html" rel="nofollow">http:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;libc&#x2F;manual&#x2F;html_node&#x2F;Hooks-for-...</a>
评论 #12713450 未加载
IpV8over 8 years ago
We use something similar to this with object creation&#x2F;deletion too. We set up a macro called watchallocation and watchdelete that keeps track of when objects get new&#x27;ed and deleted so we can track memory leaks. In release mode they just vanish. Quite helpfull