C#分块阵 [英] C# chunked array

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

问题描述

我需要分配简单结构(1 GB RAM)的非常大的阵列。一些分配/解除分配之后,内存成为碎片和内存不足异常。

I need to allocate very large arrays of simple structs (1 GB RAM). After a few allocations/deallocations the memory becomes fragmented and an OutOfMemory exception is thrown.

这是在32位。我宁可不使用64位因性能损失,我得到的 - 同样的应用程序运行在64位模式慢30%

This is under 32 bit. I'd rather not use 64 bit due to the performance penalty I get - the same application runs 30% slower in 64 bit mode.

您知道这在块分配内存的IList兼容阵列的一些实现的,而不是一下子?这将避免我的记忆碎片问题。

Are you aware of some implementations of IList compatible arrays which allocate memory in chunks and not all at once? That would avoid my memory fragmentation problem.

推荐答案

乔希·威廉姆斯presented一个 BigArray< T> 使用一个分块阵他的博客类:

Josh Williams presented a BigArray<T> class on his blog using a chunked array:

BigArray&LT ; T&GT; ,让周围2GB的数组大小限制

BigArray<T>, getting around the 2GB array size limit

您会发现此相关的问题更多有用信息:

You will find more useful information in this related question:

C#规模庞大2-暗淡阵列

一个简单的点对点修复可能使您的应用程序的3GB开关。这样做使应用程序能够使用比32位的Windows 2GB的每个进程限制更多。但是,要知道的最大物体大小的CLR允许还是2GB。交换机可以使用后建的行动为您的主执行程序被启动:

A simple ad-hoc fix might be to enable the 3GB switch for your application. Doing so allows your application to use more than the 2GB per-process limit of 32-bit Windows. However, be aware that the maximum object size that the CLR allows is still 2GB. The switch can be enabled using a post-built action for your main executable:

call "$(DevEnvDir)..\tools\vsvars32.bat"
editbin.exe /LARGEADDRESSAWARE "$(TargetPath)"

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

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