带有 gcAllowVeryLargeObjects 的 OutOfMemoryException [英] OutOfMemoryException with gcAllowVeryLargeObjects

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

问题描述

我正在使用带有相当大(虽然不是很深)的项目图的 BinarySerializer.我有 8GB 内存,由 12Gig 交换支持,并且在序列化预期时出现 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).

有什么我可以做的事情来支持序列化这个/获得相同功能集但可能会得到结果的方法吗?

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 在 x86 和 x64 操作系统上作为 32 位进程运行.因此,即使在 x64 操作系统上设置了 gcAllowVeryLargeObjects,您也会遇到 4GB 的地址空间限制(x86 上为 2GB).

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.

细节和历史可以在以下答案中找到:首选 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?

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

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