As per this website here,the
MaxSize of an array can be
more than 2GB in the
x64 environments and the actual elements it can hold is
So,I've made my app.config like :
<configuration> <runtime> <gcAllowVeryLargeObjects enabled="true" /> </runtime> </configuration>
and my array declaration and initialization is :
int idsCount = 999999999; long ids = new long[idsCount];
which is much less than the
UInt32.MaxValue,but an OutofMemory Exception was thrown.
Am I doing any mistake?
My Framework version is also
The basic check-list for this failure:
Watch out for the Visual Studio Hosting process that's enabled by default when you run your program with the debugger attached. It uses a different .config file, yourapp.vshost.exe.config. Quickly eliminate this kind of mishap by disabling the option, Project + Properties, Debug tab.</li> <li>
This can only work when your process runs in 64-bit mode, not the default for a new project. Project + Properties, Build tab, be sure to have the Platform target set to AnyCPU and the "Prefer 32-bit mode" checkbox unticked.</li> <li>
While you are there, click the Application tab and double-check the Target framework setting. Must be 4.5 or higher of course.</li> <li>
The Windows version matters, different versions have different limits for the maximum VM size of a process. Review this MSDN page and locate your Windows version and edition. You'd run into trouble with Windows 7 Home Basic for example, 8 Gigabytes max.</li> <li>
Large allocations in 64-bit mode can fail on a commit failure. Committing is the technical term for reserving space in the operating system's paging file. It acts as the backing-store in case your large array needs to be paged-out to make room for other processes. Pretty much guaranteed to happen if your machine doesn't have well over 8 Gigabytes of RAM available. You might have the size limit set too low or the OS can't grow the paging file quick enough to give you the space you need. Demonstrated well in this blog post by Mark Russinovich.</li> </ul>
long is 64 bits, or 8 bytes. The array
ids is dimensioned for one less than one billion entries, at 8 bytes per entry. That array as defined will use around 8GB.