【问题标题】:Mtrace Physical Memory Allocation LogMtrace 物理内存分配日志
【发布时间】:2014-11-26 22:05:30
【问题描述】:

我想问我是否可以使用 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

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

【问题讨论】:

    标签: c memory virtual mtrace


    【解决方案1】:

    所有暴露给用户空间应用程序的地址,包括mtrace() 显示的地址,都是虚拟内存地址。

    【讨论】:

      猜你喜欢
      • 2011-09-26
      • 2014-08-24
      • 2014-11-11
      • 2018-09-07
      • 2015-01-26
      • 1970-01-01
      • 2013-12-26
      • 1970-01-01
      • 2020-01-10
      相关资源
      最近更新 更多