哪里的malloc()/ free()的存储分配尺寸和地址? [英] Where Do malloc() / free() Store Allocated Sizes and Addresses?

查看:248
本文介绍了哪里的malloc()/ free()的存储分配尺寸和地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里malloc()和free()的存储分配的地址及其大小(Linux的GCC)?我读过一些实现实际分配的内存在什么地方存储它们,但我无法证实,在我的测试。

where do malloc() and free() store the allocated addresses and their sizes (Linux GCC)? I've read that some implementations store them somewhere before the actual allocated memory, but I could not confirm that in my tests.

的背景下,也许有人有另一个提示此:
我尝试一点点,以便确定在其它处理的串的电流值进行分析的过程的堆存储器。
访问过程的堆内存,并通过它漫步是没有问题的。然而,由于该串的值更改和过程中的每个时间分配存储器的一个新的部分,该字符串的地址变更。
因为字符串有固定的格式,它仍然很容易找到,但有几个变化后的字符串旧版本仍然在堆内存(可能获释,但仍然不重用/覆盖),因此我不能告诉该字符串是当前之一。

The background, maybe someone has another tip for this: I'm experimenting a little bit with analyzing the heap memory of a process in order to determine the current value of a string in the other process. Accessing the process heap memory and strolling through it is no problem. However, because the value of the string changes and the process allocates a new part of the memory each time, the string's address changes. Because the string has a fixed format it's still easy to find, but after a few changes the old versions of the string are still in the heap memory (probably freed, but still not reused / overwritten) and thus I'm not able to tell which string is the current one.

所以,为了仍然觉得目前的一个我想检查一个字符串我在寻找记忆仍然使用对地址的malloc /自由知道它的地址比较一下。

So, in order to still find the current one I want to check if a string I find in the memory is still used by comparing its address against the addresses malloc/free know about.

Ciao的,
艾玛

ciao, Elmar

推荐答案

有大量的其中的malloc /免费可存储的存储区的大小的方法。例如,它可能只是malloc返回区域之前被存储。或者它可以被存储在查找表中其它地方。或者它可能是隐含存储:有些地区可能会为分配的具体尺寸预留

There are lots of ways in which malloc/free can store the size of the memory area. For example, it might be stored just before the area returned by malloc. Or it might be stored in a lookup table elsewhere. Or it might be stored implicitly: some areas might be reserved for specific sizes of allocations.

要了解如何在Linux下(glibc的)C库这样做,得到 HTTP源$ C ​​$ C:/ /ftp.gnu.org/gnu/glibc/ 并期待在的malloc / malloc.c 文件。有一个在顶部的一些文件,它是指由Doug Lea内存分配

To find out how the C library in Linux (glibc) does this, get the source code from http://ftp.gnu.org/gnu/glibc/ and look at the malloc/malloc.c file. There is some documentation at the top, and it refers to A Memory Allocator by Doug Lea.

这篇关于哪里的malloc()/ free()的存储分配尺寸和地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆