Skip to main content
GameDev.net gamedev.net
🔒 Locked

Very strange array problem

Started by Lode Jul 12, 2004 at 2:27 PM 3 replies 350+ views
Original Post
Lode
Lode
I'm having a very annoying and weird problem with arrays. I've never had this before. I'm starting a fresh brand new source file in DevC++ 4.9.8.10, in WindowsXP. I enter the following code:

int main(int argc, char *argv[])
{
    int somearray[640][480][2];
    return 0;
}    
and if I compile and run it, I get the "sent error report to microsoft" window! If I make the array smaller, e.g. [320][240][2] I DONT get the error report window, then it behaves normally: I see the console window popping up very shortly and then closing again. What's going on here, is there something wrong with Windows that it can't handle too large arrays anymore? I'm very sure that I used very large arrays for a very long time already and never had problems with them before...
Palidine
Palidine
you have a limited amount of stack space. you are probably overstepping that amount. if you want really big arrays put them on the heap. though you can't nicely put multi-dimensional arrays on the heap so you'd have to do something like this:

[source]int main(int argc, char *argv[]){    int *somearray = new int[640*480*2];    //do some stuff    delete[] somearray;    return 0;}


alternitively you can increase the amount of stack space you're given. i think the default is 1MB or something like that. your array uses > 2MB of space if i've done my multiplication right.

-me
mackscynox
mackscynox
use somethign like

int ***_3darray;

_3darray =new int**[640];
for( long i=0 ; i<640 ; i++ ){
_3darray =new int*[480];
for( long j=0 ; j<480 ; j++ )
*_3darray =new int[2];
}

long but success (!) (i didnot try it ;)
Jolle
Jolle
Or you could do
int main(int argc, char *argv[]){    static int somearray[640][480][2];    return 0;}    

then it won't go on the stack.
Lode
Lode
Making it static helped, thanks :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.