64 位 .Net 应用程序中的内存限制? [英] Memory limitations in a 64-bit .Net application?

查看:32
本文介绍了64 位 .Net 应用程序中的内存限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的笔记本电脑上,运行 64 位 Windows 7 和 2 Gb 可用内存(根据任务管理器的报告),我能够做到:

On my laptop, running 64 bit Windows 7 and with 2 Gb of free memory (as reported by Task Manager), I'm able to do:

var x = new Dictionary<Guid, decimal>( 30 * 1024 *1024 );

如果我手头没有配备更多 RAM 的计算机,我想知道这是否可以扩展,以便在具有 4 Gb 可用内存的计算机上,我将能够分配 60M 项目而不是仅"30M 等等在吗?

Without having a computer with more RAM at my hands, I'm wondering if this will scale so that on a computer with 4 Gb free memory, I'll be able to allocate 60M items instead of "just" 30M and so on?

或者在我能够消耗所有可用 RAM 之前,我会遇到其他限制(.Net 和/或 Windows)吗?

Or are there other limitations (of .Net and/or Windows) that I'll bump into before I'm able to consume all available RAM?

更新: 好的,所以我不能分配大于 2 Gb 的单个对象.知道这一点很重要!但是我当然很想知道我是否能够通过像这样分配 2 Gb 块来充分利用所有内存:

Update: OK, so I'm not allowed to allocate a single object larger than 2 Gb. That's important to know! But then I'm of course curious to know if I'll be able to fully utilize all memory by allocating 2 Gb chunks like this:

  var x = new List<Dictionary<Guid, decimal>>();
  for ( var i = 0 ; i < 10 ; i++ )
    x.Add( new Dictionary<Guid, decimal>( 30 * 1024 *1024 ) );

如果计算机有 >20Gb 的可用内存,这会起作用吗?

Would this work if the computer have >20Gb free memory?

推荐答案

.NET 中的所有对象都有 2 GiB 的限制,您永远不能创建超过 2 GiB 的单个对象.如果你需要一个更大的对象,你需要确保这些对象是由小于 2 GiB 的部分构建的,所以你不能有大于 2 GiB 的连续位数组或大于 512 MiB 的单个字符串,我不是对字符串完全确定,但我已经对这个问题进行了一些测试,当我尝试分配大于 512 MiB 的字符串时,出现了 OutOfMemoryExceptions.

There's a 2 GiB limitation on all objects in .NET, you are never allowed to create a single object that exceeds 2 GiB. If you need a bigger object you need to make sure that the objects is built from parts smaller than 2 GiB, so you cannot have an array of continuous bits larger than 2 GiB or a single string longer larger than 512 MiB, I'm not entirely sure about the string but I've done some testing on the issue and was getting OutOfMemoryExceptions when I tried to allocate strings bigger than 512 MiB.

这些限制虽然受堆碎片的影响,即使 GC 确实尝试压缩堆,大对象(这在 80K 左右有点任意交叉)最终会在大对象堆上没有压实.严格来说,也有一点附带说明,如果您能将短期分配维持在此阈值以下,那么对您的整体 GC 内存管理和性能会更好.

These limits though are subject to heap fragmentation and even if the GC does try to compact the heap, large objects (which is somewhat of an arbitrary cross over around 80K) end up on the large object heap which is a heap that isn't compacted. Strictly speaking, and somewhat of a side note, if you can maintain short lived allocations below this threshold it would be better for your overall GC memory management and performance.

这篇关于64 位 .Net 应用程序中的内存限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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