I just made a multidimensional array that was 1024 x 1024 x 1024. I get an OutOfMemory exception. What is the largest size multidimensional array that is safe to use? I’m doing this in VB.net so all .net answers are acceptable.
EDIT
When I said safe, I mean, a good size for just about any computer. What size would run smoothly on a 32bit operating system. I didn’t realize that the 1024 size was 4G. I’m hoping for something a 16th of that.
.NET objects can’t be larger than 2 gigabytes. Even then, on a 32-bit operating system it is very unlikely to find a hole in addressable virtual memory space large enough to fit such a large array. You can get about 600 megabytes right after your program starts, rapidly going down hill from there after the address space starts getting fragmented. Bombing on a 90 MB allocation when there’s still half a gig free space is not terribly unusual.
You’ll need to use jagged arrays and a 64-bit operating system. And a bit of introspection if you really need such a massive array. Arrays are kinda old school after System.Collections.Generic became available. With collection classes that are as fast as an array and only let you pay for what you actually use. Recommended.