malloc 和 free 的代码

发布于 2024-11-17 14:43:02 字数 95 浏览 6 评论 0原文

在哪里可以找到 gcc 编译器目前使用的 malloc 代码?我实际上想编写自己的 malloc 函数,该函数与原始函数略有不同。我知道我可以使用钩子等,但我想看看真正的代码。

Where can I find the code for malloc my gcc compiler is using at the moment? I actually want to write my own malloc function which will be a little different from the original one. I know I can use hooks et all, but I want to see the real code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜味超标? 2024-11-24 14:43:02

malloc 的 POSIX 接口在这里定义

如果您想了解 GNU/Linux (glibc) 中的 C 库如何实现 malloc,请从 http://ftp.gnu.org/gnu/glibc/ 或浏览 git 存储库 并查看 malloc/malloc.c 文件

还有 Doug Lea 的内存分配器 的基本文档,描述了m(emory)alloc(ator) 的理论(仔细阅读本文,然后决定是否真的需要实现自己的 malloc)。

The POSIX interface of malloc is defined here.

If you want to find out how the C library in GNU/Linux (glibc) implements malloc, go and get the source code from http://ftp.gnu.org/gnu/glibc/ or browse the git repository and look at the malloc/malloc.c file.

There is also the base documentation of the Memory Allocator by Doug Lea that describes the theory of a m(emory)alloc(ator) (read this carrefully, and then decide if you really need to implement your own malloc).

爱本泡沫多脆弱 2024-11-24 14:43:02

旧版本站点1查找相应版本的 glibc或此处。例如,如果您使用的是 glib 2.9,则它位于此存档。查找文件 malloc/malloc.c

您会发现它不是一段简单的库代码。


1 看起来他们在glibc-2.9之后改变了目录结构。

Look in the appropriate release of glibc at the old release site1 or here. For example, if you are using glib 2.9, it is in this archive. Look for the file malloc/malloc.c.

You will see that it is not a trivial piece of library code.


1 It looks like they changed the directory structure after glibc-2.9.

找个人就嫁了吧 2024-11-24 14:43:02

malloc() 应该在 glibc 中。

进一步阅读
多线程
C++ 分配
技巧[视频]

malloc() should be in glibc.

Further Reading
Multithreading
C++ allocation
tricks [Video]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文