Pre-Main() stack-overflow with SDL

Started by
34 comments, last by Twiggy 19 years ago
Quote:Original post by DerAnged
MapTile *Map[2000][2000]; // The map tiles array.

MapTile *VisibleMap[300][300];

Are you sure you need a 3 dimensional array?


3D? I only see 2
Advertisement
Quote:Original post by quasar3d
Quote:Original post by DerAnged
MapTile *Map[2000][2000]; // The map tiles array.

MapTile *VisibleMap[300][300];

Are you sure you need a 3 dimensional array?


3D? I only see 2


I am extremely tired, but right now i am under the assumtion that becasue the * is making it a pointer, it is a 3 dimensional array, in ways, ie:

char* name;
can be used to a point like
char name[255];

but then again i am seeing how i am totally wrong most likely, as that is not always the case.
It works! It absoloutly works! Even my stupid old computer's teacher couldn't solve it! [wow]

Thanks! You all got my rating. :)

Now all I have left is to fix to prog and ask these following questions:

1. How did you know that the size of the array is exactly 16MB?
2. How did you know if I do it pointer-less it goes straight into the stack (for temporary use)?
3. Is there a way to incerse the stack's size?

PLease explaing my mistakes, I would like to know from them! :)

You have my thanks again, oh gurus of great computer wisdom.

Here's a treat for your help - one of the funniest net-flash-toons ever made: http://www.illwillpress.com/vault.html
___________________________"Peg, is there a certain reason that cactus is standing in the place where my alarm clock should be?"
Quote:Original post by Twiggy
It works! It absoloutly works! Even my stupid old computer's teacher couldn't solve it! [wow]

Thanks! You all got my rating. :)

Now all I have left is to fix to prog and ask these following questions:

1. How did you know that the size of the array is exactly 16MB?
2. How did you know if I do it pointer-less it goes straight into the stack (for temporary use)?
3. Is there a way to incerse the stack's size?

PLease explaing my mistakes, I would like to know from them! :)

You have my thanks again, oh gurus of great computer wisdom.

Here's a treat for your help - one of the funniest net-flash-toons ever made: http://www.illwillpress.com/vault.html


2000 * 2000 * 4 /1000000 = 16.
Why do you multiply it with 4/100000 ?

The reason I set it to 2000x2000, was because I couldn't determine the size needed for the map before I executed the main project, so I just gave it a big size so that almost every 'map size' that i will want to use will be smaller than that and fit right in the array.

So, how can I determine the size of an inside-class two-dimensoinal array?

I mean, how can I solve the problem?
___________________________"Peg, is there a certain reason that cactus is standing in the place where my alarm clock should be?"
4 = (sizeof(Map*))

And im having trouble explaining the 1000000
The 1,000,000 presumably stems from the fact that 1,000,000 bytes is roughly 1 MB (actually, 1 "MiB" is 1024*1024=1,048,576 bytes).
Quote:Original post by Miserable
The 1,000,000 presumably stems from the fact that 1,000,000 bytes is roughly 1 MB (actually, 1 "MiB" is 1024*1024=1,048,576 bytes).


That's the ticket, i kept wanting to say bits.
Quote:Original post by Twiggy
1. How did you know that the size of the array is exactly 16MB?
2. How did you know if I do it pointer-less it goes straight into the stack (for temporary use)?
3. Is there a way to incerse the stack's size?

1) 2000 elements * 2000 elements = 4000000 elements. Each element is 4 bytes (size of a pointer on a 32-bit OS/compiler is 4 bytes), so that's 16000000 bytes. There are roughtly 1000000 bytes in a Mb, so that's 16Mb (Actually, as others have said, there's 1048576 bytes in a Mb, so the array is 15.26Mb)

2) That's just the way it works. If it's not allocated with new[] or new, then it goes on the stack

3) Yes, but you *really* shouldn't need to. It's a compiler option. For VC 2003, it's in project settings -> Linker -> System -> Stack Reserve Size, and set it to whatever you like.
The default is 1Mb in MSVC, I don't know about other compilers.
Thanks! :)

Again -> So how can I determine the size of the arrays before run-time?
___________________________"Peg, is there a certain reason that cactus is standing in the place where my alarm clock should be?"

This topic is closed to new replies.

Advertisement