OutOfMemoryException异常与gcAllowVeryLargeObjects [英] OutOfMemoryException with gcAllowVeryLargeObjects

查看:813
本文介绍了OutOfMemoryException异常与gcAllowVeryLargeObjects的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是与BinarySerializer一个相当大的(虽然不是很深)项目的图形。我有交换的12Gig支持内存8GB和我得到一个OutOfMemoryException序列化时,预计在(这是可能的图形可能接近去或超过2GB)。

I'm using a BinarySerializer with a pretty big (althought not very deep) graph of items. I have 8GB of ram backed by 12Gig of swap and i'm getting an OutOfMemoryException when serializing which is expected ( it's possible the graph could go near or over 2Gb).

然而,当我使用gcAllowVeryLargeObjects它没有更好的,我仍然得到同样的异常,我的东西,应该在内存中(至少与交换)持有肯定的工作。

However when i use gcAllowVeryLargeObjects it's no better, i still get the same exception and i'm definately working on something that should hold in memory (at least with the swap).

有什么我可以做些什么来支持序列化这一/一种方式来获得相同的功能设置,但得到的结果chuncks可能?

Is there anything i could do to support serializing this / a way to get the same feature set but getting the result in chuncks maybe?

有什么特别的我的序列化代码

There's nothing special about my serialization code :

    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();
    }



对象我是序列化包含的项目阵列是自己包含数组等,但完整的图形本身是不是说:大的(它索引数据的结果,从源头上,已经只有大约1GB的大小)。

The object i'm serializing contains arrays of items that themselves contains array etc, but the full graph itself isn't "that" large (it's the result of indexing data that, at the source, is already only around 1GB in size).

这是不是由于GC碎片或者(压缩大型堆没有帮助)。

It's not due to GC fragmentation either (compacting the large heap didn't help).

推荐答案

默认值为anycpu运行32位进程在x86和x64操作系统。因此,即使 gcAllowVeryLargeObjects 在x64操作系统设置你碰到4GB的地址空间限制(2GB在x86)。

By default AnyCPU runs as 32 bit process on both x86 and x64 OS. So even with gcAllowVeryLargeObjects set on x64 OS you run into 4GB limit of address space (2GB on x86).

要更改取消更喜欢32位的解决方案属性的属性 - >编译标签

To change uncheck "prefer 32 bit" property on solution properties -> "build" tab.

的细节和历史可在以下答案中找到:的What是的目的在"身高:32位"在Visual Studio 2012中设置,它是如何实际工作?

The details and history can be found in following answer: What is the purpose of the "Prefer 32-bit" setting in Visual Studio 2012 and how does it actually work?

这篇关于OutOfMemoryException异常与gcAllowVeryLargeObjects的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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