当RAM结束在C#中会发生什么? [英] What happens when the RAM is over in C#?

查看:120
本文介绍了当RAM结束在C#中会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是电脑高手,所以让我尽量多一点明确提出这个问题:

I'm no computer expert, so let me try to put this question a little bit more specifically:

我做一些科学计算,并计算有时需要大量的内存来存储他们的结果。前几天,我这花了4 GB的硬盘输出文件,但我有这样少的RAM。所以:

I do some scientific computations, and the calculations sometimes requires a lot of memory to store their results. A few days ago, I'd an output file that took 4 GB in hard disk, but I have this amount of RAM. So:


  • 如何在CLR(或者是别的东西吗?)有,当你运行的程序分配更多的内存内存交易比在计算机可用?它创建于HD一些swap? (我知道我可以计划放慢,但我只在内存问题利息)

  • 它是依赖于操作系统的,说如果我MONO在Linux或与VS上工作窗口?

在此先感谢!

推荐答案

我觉得去想它有用的方法是:的内存的磁盘空间。的内存的是一个快速缓存。而不是想着当我出来的RAM,系统将其交换到磁盘,我想当我有可用的RAM,系统就会将我的磁盘上存储进去。

The way I find helpful to think about it is: memory is disk space. RAM is a fast cache. Rather than thinking "when I'm out of RAM, the system will swap it to disk", I think "when I have available RAM, the system will move my on-disk memory into it".

这是倒退,从大多数人怎么想,但我觉得它帮助。 RAM只是一个性能优化;你可以分配的内存量的实际限制是可用磁盘空间。

That's backwards from how most people think about it, but I find it helps. RAM is just a performance optimization; the real limit on how much memory you can allocate is available disk space.

当然是比这更复杂。在32位操作系统的每个进程得到2十亿字节的用户地址空间的。 (与同为内核地址空间,但让我们忽略这一点。)内存的每一页都可以访问,不管是在RAM或磁盘上,必须在该地址空间。你可以有2个以上十亿字节分配的,没有问题。但是,你只能满足2 GB的它一次。如果您分配了10 GB,那么它至少8GB不会被映射到地址空间。在这种情况下,你必须的取消映射的别的东西,然后映射你想要什么到地址空间中,为了得到它。

Of course it is more complicated than that. On 32 bit operating systems every process gets a 2 billion byte user address space. (And the same for the kernel address space, but let's ignore that.) Every page of memory you can access, whether it is in RAM or on disk, has to be in that address space. You can have more than 2 billion bytes allocated, no problem. But you can only address 2 GB of it at a time. If you have 10 GB allocated, then at least 8GB of it will not be mapped into address space. In that case you have to unmap something else and then map what you want into the address space in order to get at it.

此外,很多事情需要在的连续的地址空间。如果你有一个1MB的堆栈,例如,那么就需要一个亿的连续的地址空间可用的字节。

Moreover, lots of things need to be in contiguous address space. If you have a 1MB stack, for example, then there needs to be a million contiguous bytes available in the address space.

当人的运行内存不足他们不运行的RAM; RAM是刚刚超过磁盘快速缓存。他们不运行的磁盘空间不足;有大量的这一点。他们几乎总是在一个情况下没有足够的连续的地址空间来满足需求。

When people "run out of memory" they are not running out of RAM; RAM is just a fast cache over the disk. And they are not running out of disk space; there's plenty of that. They're almost always in a situation where there is insufficient contiguous address space to meet the demand.

CLR的内存管理器并没有实现这些花哨的地图和取消映射策略为你;基本上,你得到你的2GB的地址空间,仅此而已。如果你想要做的事花哨,说与内存映射文件,这是由你来编写代码来自己管理的内存。

The CLR memory manager does not implement these fancy map-and-unmap strategies for you; basically, you get your 2GB address space and that's it. If you want to do something fancy, say with memory mapped files, that's up to you to write the code to manage the memory yourself.

这篇关于当RAM结束在C#中会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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