TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: Flexible C memory allocation scheme with leak checking

52 点作者 mulle_nat超过 8 年前

4 条评论

ktRolster超过 8 年前
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 未加载
JoachimSchipper超过 8 年前
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 未加载
zde超过 8 年前
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 未加载
IpV8超过 8 年前
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