Can't create huge arrays

前端 未结 2 1379
南旧
南旧 2020-12-06 16:33

Like many other programmers, I went into primes, and as many of them, what I like is the challenge, so I\'m not looking for comment like Atkin did this faster than you d

相关标签:
2条回答
  • 2020-12-06 17:11

    From your link:

    Using this element in your application configuration file enables arrays that are larger than 2 GB in size, but does not change other limits on object size or array size:

    The maximum index in any single dimension is 2,147,483,591 (0x7FFFFFC7) for byte arrays and arrays of single-byte structures, and 2,146,435,071 (0X7FEFFFFF) for other types.

    See also What is the maximum length of an array in .NET on 64-bit Windows:

    An array could theoretically have at most 2,147,483,647 elements, since it uses an int for indexing.

    0 讨论(0)
  • 2020-12-06 17:27

    If you hit the bounds of the integer max range, you can opt to use a long-index-based array.

    The problem is that this isn't supported by the C# indexer properties, which uses int. You can build them by hand though by using Array.CreateInstance(Type, long[]).

    Note you have to get the values using Array.GetValue(long).

    0 讨论(0)
提交回复
热议问题