我有一台 2 GB 的机器。在运行我的 exe 之前,我有 1.1 GB 的可用内存。当我运行下面只有一行的 exe 时,出现内存不足异常。
我预计以下行将使用大约 6 亿字节。 MemoryStream 类使用的内存是否多于初始化容量?
MemoryStream memory = new MemoryStream(600000000);
最佳答案
根据以下问答,很可能是因为您的EXE无法分配600兆的连续内存。 (我试图在文档中找到一些东西,这是我在短时间内能想到的最好的东西。)
"An “out of memory” error almost never happens because there’s not enough storage available; as we’ve seen, storage is disk space, and disks are huge these days. Rather, an “out of memory” error happens because the process is unable to find a large enough section of contiguous unused pages in its virtual address space to do the requested mapping."
有趣的是,该答案链接到 Eric Lippert's博客文章: http://blogs.msdn.com/b/ericlippert/archive/2009/06/08/out-of-memory-does-not-refer-to-physical-memory.aspx
关于.net - MemoryStream 使用了多少内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13385452/