强制将内存分配始终分配给相同的虚拟地址 [英] Force memory allocation always to the same virtual address

查看:98
本文介绍了强制将内存分配始终分配给相同的虚拟地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用一种检测工具 Pin 根据我的变量的内存地址来计算一些统计信息.我想用我的检测工具收集的信息重新运行程序,但是对于虚拟内存地址,通过不同的运行保持相同至关重要.

I'm experimenting with Pin, an instrumentation tool, which I use to compute some statistics based on memory address of my variables. I want to re-run my program with the information gathered by my instrumentation tool, but for that it's crucial that virtual memory addresses remain the same through different runs.

通常,我应该让操作系统处理内存分配,但是在这种情况下,我需要某种方式来强制它始终分配给相同的虚拟地址.特别是,我对一个很长的数组感兴趣,尽管我可以使用其他数组,但我目前正在使用numa_alloc_onnode()进行分配.

In general, I should let the OS handle memory allocation, but in this case I need some kind of way to force it to always allocate to the same virtual address. In particular, I'm interested in a very long array, which I'm currently allocating with numa_alloc_onnode(), though I could use something else.

正确的进行方式是什么?

What would be the correct way to proceed?

谢谢

推荐答案

您可以尝试mmap(2).

You could try mmap(2).

程序的检测版本将使用与原始程序不同的内存布局,因为引脚需要用于动态翻译的内存等,并且会更改内存布局. (如果我没记错的话)

The instrumented version of your program will use a different memory layout than the original program because pin needs memory for the dynamic translation etc. and will change the memory layout. (if I recall correctly)

这篇关于强制将内存分配始终分配给相同的虚拟地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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