Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello
i want:
char[,,] array3d = new char[1000,1000,1000];
but:
Exception of type 'System.OutOfMemoryException' was thrown.
Do i can use of Hard replace RAM?
sorry My english language is poor
please help me..
thanks...
Posted
Comments
Sid_Joshi 26-Jul-14 2:23am    
Can you please explain me your program flow and what you wants to do?

1 solution

No single object in .NET can exceed 2GB: that is an absolute limit. And an array is a single object.
Now, it might not seem that a 3D array of 1000 elements would exceed 2GB - it's only 1,000,000,000 characters, isn't it?
But... char is 16 bits (because it's unicode) so that's 2,000,000,000 bytes just in the direct chars, plus the overhead that a 3D array is likely to acquire to support the various dimensions. Basically, you could do it with byte values, but char just pushes it over the edge.

You could do it as a jagged array:
C#
char[][][] array3d = new char[1000][][];
for (int x = 0; x < 1000; x++)
    {
    array3d[x] = new char[1000][];
    for (int y = 0; y < 1000; y++)
        {
        array3d[x][y] = new char[1000];
        }
    }

Because that doesn't create one single huge object.
Will be slow, though!
 
Share this answer
 
Comments
Dilan Shaminda 26-Jul-14 2:42am    
my 5+ sir.Nice explanation :-)
Member 10825775 26-Jul-14 9:13am    
hithanks very much..
I do it, but yet have: 'System.OutOfMemoryException' !
because I have another array in my application too; so please say to me a original solution that (char[][][] array3d) use of Hard memory replace Ram.
please help me
best regards..
OriginalGriff 26-Jul-14 10:00am    
Sorry?
I don't understand what you are trying to say there. Could you please try to rephrase it, or write in in your native language and use Google Translate to convert it to English?
Member 10825775 26-Jul-14 14:17pm    
Excuse me
Is it used in the array, rather than go through the hard drive can provide?
or
I needed space in the array instead of the RAM is limited by hard drive supply
Is this possible?
Thank you for your attention
best regards..
OriginalGriff 27-Jul-14 3:21am    
I'm still not sure I understand you, but...the HDD space is only relevant when you run out of physical RAM and the operating system starts paging to disk. Under normal circumstances this is transparent to you - the only thing you might notice is that the application slows down a lot as memory data is copied onto / off of hard drive.

How many of these huge arrays have you got? (And why? :laugh: )

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900