访问由程序分配的内存外部。 (访问其他应用的内存) [英] Accessing outside the memory allocated by the program. (Accessing other app's memory)

查看:194
本文介绍了访问由程序分配的内存外部。 (访问其他应用的内存)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以访问(读取或释放)分配给程序的内存之外的内存块,而不会发生访问冲突异常。
除此之外,我真正想要了解的是内存清理器(系统垃圾回收器)是如何工作的。我一直想写这样的程序。 (语言不是问题)



预先感谢:)

解决方案

简单的答案(少我错了),没有。一般来说这不是一个好主意,有两个原因。首先是因为它会导致程序和其他程序之间的信任问题(更不用说我们人类也不会信任你的应用程序)。其次是如果您能够访问另一个应用程序内存并在应用程序不知道的情况下进行更改,则会导致应用程序崩溃(病毒也会这样做)。



垃圾收集器是从运行时调用的。运行时拥有了内存空间,并允许其他应用程序在该内存空间中存活。这就是垃圾收集器可以存在的原因。你将不得不创建一个OS分配内存的运行时,让运行时在它的权限下执行应用程序,并在它的权限下使用GC。您将需要允许一些仪器或API允许应用程序开发人员从运行时(而非OS)请求内存,并且您的运行时不仅可以响应此类请求,还可以跟踪它的内存空间分配给该应用程序。您可能需要有一个框架(一组DLL),使这些调用可供应用程序使用(开发人员将使用它们在应用程序中形成请求)。



您必须确保您的垃圾收集器不会除去正在执行的应用程序使用的内存之外的内存,因为您可能同时在运行时内运行了多个应用程序。



希望这有助于。


Is there a way to access (read or free) memory chunks that are outside the memory that is allocated for the program without getting access violation exceptions. Well what I actually would like to understand apart from this, is how a memory cleaner (system garbage collector) works. I've always wanted to write such a program. (The language isn't an issue)

Thanks in advance :)

解决方案

The simple answer (less I'm mistaken), no. Generally it's not a good idea for 2 reasons. First is because it causes a trust problem between your program and other programs (not to mention us humans won't trust your application either). second is if you were able to access another applications memory and make a change without the application knowing about it, you will cause the application to crash (also viruses do this).

A garbage collector is called from a runtime. The runtime "owns" the memory space and allows other applications to "live" within that memory space. This is why the garbage collector can exist. You will have to create a runtime that the OS allocates memory to, have the runtime execute the application under it's authority and use the GC under it's authority as well. You will need to allow some instrumentation or API that allows the application developer to "request" memory from your runtime (not the OS) and your runtime have a way to not only response to such a request but also keep track of the memory space it's allocating to that application. You will probably need to have a framework (set of DLL's) that makes these calls available to the application (the developer would use them to form the request inside their application).

You have to be sure that your garbage collector does not remove memory other then the memory that is used by the application being executed, as you may have more then 1 application running within your runtime at the same time.

Hope this helps.

这篇关于访问由程序分配的内存外部。 (访问其他应用的内存)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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