非托管内存和托管内存

发布于 2024-08-02 17:24:07 字数 135 浏览 10 评论 0原文

非托管托管内存到底是什么? 有人可以简单地解释一下我吗?

另外,当托管内存概念应用于 RAM(称为托管 RAM)时,到底意味着什么。 “托管 RAM”和“非托管 RAM”有哪些具体细节?

what exactly are un-managed and managed memory?
can anybody explain me in brief?

Also, what exactly would mean when the managed-memory concept is taken to RAM, calling managed-RAM. What are some of the specifics about "managed RAM" and "un-managed-RAM"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恬淡成诗 2024-08-09 17:24:07

都是相同的物理内存。区别在于谁在控制它。

Microsoft 的定义是,托管内存由垃圾收集器 (GC) 进行清理,即定期确定物理内存的哪些部分正在使用、哪些部分未使用的进程。

非托管内存由其他东西(例如您的程序或操作系统)清理。

非托管内存这个术语有点像第一次世界大战,直到第二次世界大战之后才被称为非托管内存。以前它只是内存。

It is all the same physical memory. The difference is who is controlling it.

The Microsoft definition is that managed memory is cleaned up by a Garbage Collector (GC), i.e. some process that periodically determines what part of the physical memory is in use and what is not.

Unmanaged memory is cleaned up by something else e.g. your program or the operating system.

The term unmanaged memory is a bit like the World War 1, it wasn't called that until after World War 2. Previously it was just memory.

笑咖 2024-08-09 17:24:07

可以从不同的方面来理解非托管内存

在较高级别上,您运行的应用程序可以分为两类:非托管代码托管代码托管代码运行时管理,例如.Net和Java。运行时提供了重要的功能,例如自动内存管理(通过垃圾收集器)。 非托管代码是运行 ac/c++ 程序的方式。开发人员全权负责管理程序的所有内容,包括内存部分(通过 mallocfree 等 API)。

在较低且具体的层面上,例如在.Net世界中,内存管理也可以分为托管非托管两部分。这其实是令人困惑的一点。因为如上所述,.Net运行时提供了GC,可以自动处理内存分配和释放。为什么仍然有非托管内存?这里的关键点是,非托管部分不是内存本身,而是绑定到内存的底层资源。一般来说,这些是操作系统级别的资源,如文件网络连接数据库连接。 GC 可以收集内存,但它不知道如何处理这些底层系统级资源。所以在某种程度上,它不受运行时的控制。然后开发人员需要做一些事情来帮助运行时正确处理这种情况(例如.Net世界中的Dispose方法调用)。

There are different aspects to understand unmanaged memory.

In the higher level, the applications you run can be classified into two categories: unmanaged code and managed code. The managed code is managed by a runtime, like .Net and Java. The runtime provides important functionalities like automatic memory management(by garbage collector). And the unmanaged code is the way you run a c/c++ program. The developers have the full responsibility to manage everything of the program, including the memory part(by APIs like malloc and free).

In a lower and specific level, for example, in .Net world, the memory management can also be classified into managed and unmanaged two parts. This is in fact the confusing point. Because as mentioned above, the runtime of .Net provide GC which can handle the memory allocation and release automatically. Why there are still unmanaged memory? The critical point here is that the unmanaged part is not the memory itself, instead it's the underlying resources bound to the memory. Generally, these are operating system level resource, like file, network connection and database connection. The GC can collect the memory but it doesn't know how to handle those underlying system level resource. So to some extend, it's out of control of the runtime. Then the developer need to do something to help the runtime to handle this case properly(For example, the Dispose method call in .Net world).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文