Код: Выделить всё
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config
< /code>
У меня есть пользовательский класс для коллекций, превышающих 2 ГБ с кучевым массивом: < /p>
public class BulkCollection : IEnumerable, ICloneable
{
private const int ChunkSize = 1000000000;
private readonly T[][] _chunks;
public long Count { get; }
public BulkCollection(long count)
{
Count = count;
long numberOfChunks = count / ChunkSize;
long lastChunkSize = count % ChunkSize;
_chunks = new T[numberOfChunks + (lastChunkSize > 0 ? 1 :0)][];
for (long i = 0; i < numberOfChunks; i++)
{
_chunks = new T[ChunkSize];
}
if (lastChunkSize > 0)
{
_chunks[^1] = new T[lastChunkSize];
}
}
public BulkCollection(BulkCollection bulkcollection)
{
}
public T this[long index]
{
get
{
if (index < 0 || index >= Count)
{
throw new IndexOutOfRangeException();
}
long chunkIndex = index/ChunkSize;
int itemIndexInChunk = (int)(index % ChunkSize);
return _chunks[chunkIndex][itemIndexInChunk];
}
set
{
if (index < 0 || index >= Count)
{
throw new IndexOutOfRangeException();
}
long chunkIndex = index / ChunkSize;
int itemIndexInChunk = (int)(index % ChunkSize);
_chunks[chunkIndex][itemIndexInChunk] = value;
}
}
public IEnumerator GetEnumerator()
{
return new BulkEnumerator(this);
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public object Clone()
{
return this.MemberwiseClone();
}
}
< /code>
in для цикла: < /p>
for (long i = 0; i < numberOfChunks; i++)
{
_chunks = new T[ChunkSize];
}
< /code>
Исключено исключение: < /p>
Исключение Type 'System.outofmemoryException' был брошен
system.outofmemoryexception решение. Спасибо
Подробнее здесь: https://stackoverflow.com/questions/797 ... moryexcept