How much is the theoretical maximum length of a C # array? Once asked over Niang, Google, seemingly did not come to a more accurate answer, nothing is what Int32 the maximum value ah what, today finally decided to write a software to test their own, in a few different computers inside the actual test to see how big?
Just do it. The maximum length of several common types, such as bool array, int array, string array, long array, and float array, is found by using binary search algorithm, and the results are as follows on three computers respectively:
Computer \ Array Type |
bool |
Int |
String |
Long |
Float |
Computer 1-PC |
2147483591 |
536870897 |
268435447 |
268435448 |
536870897 |
Computer 2-x3650 Server |
2147483591 |
536870897 |
268435447 |
268435448 |
536870897 |
Computer 3-x250 Notebook |
2147483591 |
536870897 |
268435448 |
268435448 |
536870897 |
Basic configuration of Computer 1-pc:
Computer 2-x3650 Server:
Computer 3-x250 Notebook:
From the above table, it can be very clear that these several system environment of various types of array of the maximum length, a bit strange is, a string type array, three system environment a little different, looking at the expert pointing.
PS: In the process of writing the test software, found and realized a debug and release program differences, degrees Niang and Google on most of the statement are, release more lightweight, do a lot of optimization, the program runs more efficient, but really embodied in the program is, the definition of an array, For example int[] list = new Int[1000],debug is immediately allocated memory space, and release, if not used is not allocated memory space, which led me to the test program at the very beginning of the situation, the debug mode is running well, And the release mode is not normal, because I am by catching an exception to determine the maximum length of the type array in the system
C # Array size analysis (with Debug and release differences remembered during the test)