I want to declare array 2^32 size on 32 bit OS for integer hash table.tell me what to do? It is giving me Out of memory exception.
Asked
Active
Viewed 178 times
-2
-
Would be great to see some code or atleast tell us why you need a table of that size – Hatted Rooster Sep 06 '14 at 19:49
1 Answers
2
You simply can't do this. In a 32-bit CLR, all objects must be less than 2GB in size.
Even in a 64-bit CLR, you have to specify a special flag to enable larger arrays (<gcAllowVeryLargeObjects>
) - and if your array is an array of integers, you're actually asking for 16GB. It seems unlikely that you'd have that much physical memory on a 32-bit OS.
You can work around the limit to some extent by making one "logical" array composed of multiple smaller arrays, but I rarely view that as a good idea. Basically, you should either redesign or use an OS that's more suitable for your requirements. I suspect that a redesign is likely to be the best approach.

Jon Skeet
- 1,421,763
- 867
- 9,128
- 9,194
-
+1. "unlikely to have 16GB on 32 bit OS" is way too nice... You actually can't do that at all (ignoring indirect solutions like [PAE](http://msdn.microsoft.com/en-us/library/windows/desktop/aa366796%28v=vs.85%29.aspx)). – Alexei Levenkov Sep 06 '14 at 19:53
-
@AlexeiLevenkov: Things like PAE were why I didn't want to claim it to be absolutely impossible ;) – Jon Skeet Sep 06 '14 at 19:54
-
@AlexeiLevenkov: Yup, no problem. I'd like to think I have a *reasonably* thick skin, and this wasn't even a tickle ;) – Jon Skeet Sep 06 '14 at 19:58