我正在测试.Net中的集合有多大.从技术上讲,任何集合对象都可以增长到物理内存的大小.
然后,我测试的服务器,它具有16GB内存下面的代码,运行Windows 2003 Server和Visual Studio 2008,我测试两个F#和C#代码,看了看任务管理器运行时.我可以看到,在增加2GB内存之后,该程序因内存不足异常而崩溃.我确实在属性页面中将目标平台设置为x64.
open System.Collections.Generic
let d = new Dictionary<int, int>()
for i=1 to 1000000000 do
d.Add(i,i)
Run Code Online (Sandbox Code Playgroud)
我对C5集合库进行了相同的测试.结果是C5中的字典可能耗尽整个内存.代码使用C5:
let d = C5.HashDictionary<int, int> ()
for i=1 to 1000000000 do
d.Add(i,i)
Run Code Online (Sandbox Code Playgroud)
谁知道为什么?
我正在使用BinarySerializer,它有一个非常大的(尽管不是很深)项目图.我有8GB的ram支持12Gig的交换,并且在序列化时我得到一个OutOfMemoryException,这是预期的(图表可能接近或超过2Gb).
然而,当我使用gcAllowVeryLargeObjects它并不是更好,我仍然得到相同的异常,我肯定在应该保留在内存中的东西(至少与交换).
有什么我可以做的来支持序列化这个/一种方法来获得相同的功能集,但可能会得到结果?
我的序列化代码没有什么特别之处:
public static byte[] Serialize(this object o)
{
var ms = new MemoryStream();
var bf = new BinaryFormatter();
bf.Serialize(ms, o);
ms.Position = 0;
return ms.ToArray();
}
Run Code Online (Sandbox Code Playgroud)
我正在序列化的对象包含自身包含数组等的项目数组,但完整的图形本身并不"大"(这是索引数据的结果,在源处,已经只有大约1GB的大小).
这不是由于GC碎片造成的(压缩大堆没有帮助).
我有一台带有 128 GB RAM 的 64 位 PC,我使用的是 C# 和 .NET 4.5。我有以下代码:
double[,] m1 = new double[65535, 65535];
long l1 = m1.LongLength;
double[,] m2 = new double[65536, 65536]; // Array dimensions exceeded supported range
long l2 = m2.LongLength;
Run Code Online (Sandbox Code Playgroud)
我知道<gcAllowVeryLargeObjects enabled="true" />并且我已将其设置为 true。
为什么多维数组不能有超过 4294967295 个元素?我看到以下答案/sf/answers/163715821/。
我还检查了gcAllowVeryLargeObjects的文档,我看到了以下评论。
数组中的最大元素数为UInt32.MaxValue (4294967295)。
我不明白为什么有这个限制?有解决方法吗?是否计划在即将发布的 .net 版本中删除此限制?
我需要内存中的元素,因为我想计算例如使用英特尔 MKL 的对称特征值分解。
[DllImport("custom_mkl", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = false)]
internal static extern lapack_int LAPACKE_dsyevd(
int matrix_layout, char jobz, …Run Code Online (Sandbox Code Playgroud) c# arrays multidimensional-array .net-4.5 gcallowverylargeobjects
我该如何在C#中的后面代码中编写此代码?gcAllowVeryLargeObjects我不能使用配置文件。
下面是配置文件的版本
<configuration>
<runtime>
<gcAllowVeryLargeObjects enabled="true" />
</runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud) 在几次 outOfMemory 异常之后,我启用了“gcAllowVeryLargeObjects”,它工作得很好。我现在想知道为什么它不是 C# 中的默认选项(在 64 位平台上)。
纯粹是出于兼容性原因吗?还是我错过了 gcAllowVeryLargeObjects 的一个主要缺点?
问题是关于.net中数组的分配.我有一个示例程序,其中我可以得到的最大数组是长度.我将长度增加到+1它给出了outofMemory异常.但如果我保持长度并删除评论,我可以分配2个不同的大数组.两个数组的.net允许对象大小为2 gb,总内存也小于虚拟内存.有人可以提出任何想法吗?
class Program
{
static int length = 203423225;
static double[] d = new double[length];
//static int[] i = new int[15000000];
static void Main(string[] args)
{
Console.WriteLine((sizeof(double)*(double)length)/(1024*1024));
Console.WriteLine(d.Length);
//Console.WriteLine(i.Length);
Console.WriteLine(Process.GetCurrentProcess().VirtualMemorySize64.ToString());
}
}
Run Code Online (Sandbox Code Playgroud) 特定
// r is a System.Data.IDataRecord
var blob = new byte[(r.GetBytes(0, 0, null, 0, int.MaxValue))];
r.GetBytes(0, 0, blob, 0, blob.Length);
Run Code Online (Sandbox Code Playgroud)
和r.GetBytes(...)回报Int64
由于Array.zeroCreate和Array.init采取Int32如何创建一个空的数组,它是可能大于Int32.MaxValue?
我必须使用尺寸为34000x34000项的二维数组进行数学计算.
明显的问题 - CLR不可能在内存中存储如此大的数据部分.我试图使用MemoryMappedFile,但是当我试图为对象创建查看器时它也失败了:MemoryMappedFile.CreateViewAccessor().是否还有其他已存在的存储大型数组的方法?(因为我没有太多时间尝试实现自定义大数据存储)
谢谢