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

查看:593
本文介绍了在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的可用内存,我就能够分配,而不是刚30M等等60M项目对?

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?

还是有其他的限制(.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块千兆像这样充分利用所有内存:

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吉布限制,你永远不会允许创建超过2吉布一个对象。如果你需要一个更大的目标,你需要确保的对象是从零件比2吉布小建,所以你不能有连续的位比2吉布或单一字符串长度大于512 MIB大的数组,我不是完全对字符串肯定,但我做了对这个问题的一些测试,并获得OutOfMemoryExceptions当我试图来分配字符串大于512 MIB。

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)结束了在大对象堆是那不是堆T压实。严格来说有点的,和一个侧面说明,如果你能保持低于这个阈值,它会为你的整体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天全站免登陆