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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

A tiny Unix dynamic memory allocator library

24 点作者 nanxiao超过 7 年前

5 条评论

userbinator超过 7 年前
It uses calloc() which then uses... the system library's malloc(). I'm not sure what utility this has --- all it does is add some headers and footers to the allocated block in an attempt to catch overflow writes, but practically all existing malloc()s do that already.
评论 #15318341 未加载
评论 #15319372 未加载
spc476超过 7 年前
The author of this could have picked a better value to fill in the guard area. For the x86 architecture, 0xCC is a good choice. It's an unusual negative value, a largish unsigned value, most likely an invalid address (if dereferenced as a pointer) and if executed, is the INT 3 breakpoint instruction. Other architectures would require different values, but at least pick one that has a good chance of blowing something up if used.
unwind超过 7 年前
It disallows free(NULL) which the standard allows, so it's not a drop-in replacement. Hard to see the added value although allocators can be good for learning.
woahhvicky超过 7 年前
This is implemented in terms of calloc()/free(). Is this a joke? Or some kind of post-modern art? Genuinely curious, the use cases aren't clear.
评论 #15318928 未加载
fanf2超过 7 年前
phkmalloc is a real (but single-threaded) allocator and less than 1200 lines: <a href="https:&#x2F;&#x2F;svnweb.freebsd.org&#x2F;base&#x2F;stable&#x2F;4&#x2F;lib&#x2F;libc&#x2F;stdlib&#x2F;malloc.c?revision=128477&amp;view=markup" rel="nofollow">https:&#x2F;&#x2F;svnweb.freebsd.org&#x2F;base&#x2F;stable&#x2F;4&#x2F;lib&#x2F;libc&#x2F;stdlib&#x2F;mal...</a>