Reputation: 2504
As I understand there is a limit in arrays and other objects to a maximum of 2GB in .NET. I know that in 64bit machines we can use gcAllowVeryLargeObjects to get around this issue and create arrays of bigger than 2GB.
My question is whether we can use the unsafe block in C# to create an unsafe array of bigger than 2GB size (i.e. a 3GB array) in a 32bit machine.
Upvotes: 0
Views: 613
Reputation: 700312
No, that is not possible, but it's not a limitation in C# or its array implementation.
The total address space for a 32 bit machine is 4 GB. Some of that is used for hardware access, so the usable address space is about 3.5 GB, varying a bit depending on the memory hardware in the machine.
Normally the address space above 2 GB is reserved for the system, so you only have 2 GB of usable address space for your application data. As that includes your program, the stack and the heaps, there isn't even 2 GB available for the large objects heap.
It might be possible to allow more then 2 GB of the memory for user data, but still not all of the 3.5 GB as the system still needs some, and with the other things you have in memory you won't ever get much more than 2 GB available for a large object allocation.
Upvotes: 2
Reputation: 100527
While in theory you may be able to allocate large arrays in 32bit process in practice you'll run into address space fragmentation issues. I'd recommend finding some other approach as finding more than 2GB of continuous address space in 32bit process is rare.
Note that you'll also need to make sure process have "large address space aware" flag (I think by default .Net binaries have it, but check anayway).
Upvotes: 3