gpt4 book ai didi

c - Mtrace物理内存分配日志

转载 作者:行者123 更新时间:2023-11-30 17:24:55 28 4
gpt4 key购买 nike

我想问是否可以使用 mtrace() 函数,以便我的程序记录内存分配的物理地址。另外,如果我使用 mtrace() 并且能够显示用于分配的地址,这会显示物理或虚拟内存中的地址吗?

提前谢谢您。

编辑:好的,所以我运行以下代码:

#include <stdlib.h>
#include <mcheck.h>

int main(void) {

mtrace(); /* Starts the recording of memory allocations and releases */

int* a = NULL;

a = malloc(sizeof(int)); /* allocate memory and assign it to the pointer */
if (a == NULL) {
return 1; /* error */
}

free(a); /* we free the memory we allocated so we don't have leaks */
muntrace();

return 0; /* exit */

}

它给了我以下输出:

=Start
@ ./a.out:[0x80484a6] + 0x9738378 0x4
@ ./a.out:[0x80484c4] + 0x9738378
= End

地址显示在虚拟内存中还是物理内存中?

最佳答案

向用户空间应用程序公开的所有地址,包括由 mtrace() 显示的地址,都是虚拟内存地址。

关于c - Mtrace物理内存分配日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27159719/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com