如何获取对象的内存地址? [英] How to get a Memory address of the Object?

查看:416
本文介绍了如何获取对象的内存地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在c#中获取特定对象的地址?

请帮助我...

先谢谢

Is it possible to get the address of Particular Object in c#?
plz help me..
Thanks in Advance

推荐答案

.Net中的内存地址不是静态的。对象随内存管理器一直移动。你想要完成什么?
Memory address in .Net aren't static. Objects get moved around all the time by the memory manager. What are you trying to accomplish?


物理内存地址对于处于保护模式的应用程序是不存在的。这是您作为应用程序所没有的特权操作。通过简单地读取物理地址也不会得到任何结果,因为您还应该知道该物理地址上的内容以及由于不时变化的分页。操作系统不会让你受到影响而被视为安全风险。
Physical memory addresses are non-existant for applications in protected mode. This is a privileged operation that you as application do not have. You would also get nothing by simply reading physical addresses because you should also know what is on that physical address and due to paging that varies from time to time. The OS won't let you get in the way there and would be considered an security risk.


嗯,你可以这样做。你应该寻找的关键词是指针固定,不安全模式,一般来说,托管运行时指针。但是你必须要注意这个的副作用 - 答案1已经给你一个暗示。在开始使用固定指针和不安全语句之前,你应该回答上面已经提到过的问题:你想要完成什么?很少需要固定,我强烈建议找另一种方式......
Well, you can do that. The keywords you should look for are "pointer pinning", "unsafe mode" and in general, "pointers in the managed run-time". But you have to be aware of the side effects of this - the Answer 1 already gives you a hint. Before you start working with pinned pointers and "unsafe" statements you should really answer the the question already asked above: "What are you trying to accomplish?" Pinning is rarely needed and I would strongly recommend to find another way...


这篇关于如何获取对象的内存地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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