troubleshooting Question

Array System.OutofMemoryException

Avatar of tlfeet
tlfeet asked on
Visual Basic Classic
15 Comments1 Solution887 ViewsLast Modified:
Hi,

I am puzzled and looking for a workaround if possible, and some how too info.

I have an array, 4 dimensions

Per MS documentation at <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vacondeclaringarrays.asp">Declaring Array Variables</a>

No one of my dimensions is greater than 2^64 -1
actually not even close, maximum dimensions size is 256

So I could have Dim MyArray(256,256,256,256) As Integer
as the largest array [actually, do a ReDim based upon input from user, but above is maximum size]

When I have such an array, I get System.OutofMemoryException, error.
By trial and error, so far largest array that does not throw the error is 100,100,100,100
[actually I am somewhere between 100 & <130, on my machine]

But MS documentation, same link also says:
"The total size limit of an array varies, based on your operating system and how much memory is available. Using an array that exceeds the amount of RAM available on your system is slower because the data must be read from and written to disk."

OK, so I have an array larger than RAM can handle . . . I'll take the hit to speed, it can read/write to disk, but it is obviously not doing so.

The way I read MS doc is that with my large array it should be reading/writing to disk, yes it slows down program, but that is better than it throwing OutofMemoryException.

Some questions:
1. Is MS doc wrong, or is there some parameter, class, setting I need to specify to tell it to read/write large arrays? e.g. somewhere in program a line that reads in essence "OK stupid, if an array is too big for memory, read/write it to disk, like MS doc says you should"

2. Ignoring idiocy of doc for a second, is there some other way I can store the data that gets stored in the array and achieve the functionality [I know of a couple of ways myself, but they would involve major rewrite of code - read/write to a file, bust array up into parts - that is there some other object/class that could do it?]

3. I suspect MS doc is wrong. In which case how do I tell before program gets to the error, how big of an array the memory for a given machine can handle?
That is, when user specifies array size, have program do a calculation so as determine at user input time, that the array is either too big for that user's machine, or machine does have enough RAM?
And if not enough RAM for say 256^4, how big the array could be and still run?
Rather than user enters size, runs it, gets error, tries again w different value, gets error, tries again...?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 15 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros