User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion
Register FAQ Members List Calendar Arcade Today's Posts

Reply
Thread Tools Display Modes
Unread 28 Jan 2003, 08:01   #1
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
MS Visual C++: stack overflow when calling function

What is the problem here? It's a simple function of a simple object. If I call another function of the same object it works fine, but that function messes up:

Code:
terrain.loadTerrain("terrain.raw");

bool CTerrain::loadTerrain(char* filename)
{          //it doesn't even come here
	unsigned char terra[TERRAINSIZE*TERRAINSIZE];
	FILE *pFile = NULL;

etc
I've done a rebuild, and I've tried it on two different computers (one with win98, one with win2k), but the problem remains.
Structural Integrity is offline   Reply With Quote
Unread 28 Jan 2003, 08:37   #2
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
oh..... great....

I have managed to narrow the problem down to one line:
unsigned char terra[TERRAINSIZE*TERRAINSIZE];

It appears that I cannot declare a char aray of one MB (1024 * 1024)........ heh......
1024 * 1012 doesn't give a problem but anything higher gives an error.
Is there something I'm missing? Is there a limit of how much memory you can declare?!
Structural Integrity is offline   Reply With Quote
Unread 28 Jan 2003, 09:21   #3
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
Try using 'new' to allocate the memory rather than the way you're doing it. That way you won't be using the stack (which in VC++ is 1MB).

Guess how I know this? lol
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
Gayle29uk is offline   Reply With Quote
Unread 28 Jan 2003, 09:49   #4
Pitchfork
Tourist
 
Join Date: Jun 2001
Location: moon
Posts: 90
Pitchfork is an unknown quantity at this point
Re: MS Visual C++: stack overflow when calling function

Quote:
Originally posted by Structural Integrity
What is the problem here? It's a simple function of a simple object. If I call another function of the same object it works fine, but that function messes up:

Code:
terrain.loadTerrain("terrain.raw");

bool CTerrain::loadTerrain(char* filename)
{          //it doesn't even come here
	unsigned char terra[TERRAINSIZE*TERRAINSIZE];
	FILE *pFile = NULL;

etc
I've done a rebuild, and I've tried it on two different computers (one with win98, one with win2k), but the problem remains.
Code:
terrain.loadTerrain("terrain.raw");

bool CTerrain::loadTerrain(char* filename)
{          //it doesn't even come here
	unsigned char *terra[TERRAINSIZE*TERRAINSIZE] = new char[TERRAINSIZE*TERRAINSIZE];
	FILE *pFile = NULL;

etc

delete[] terra;
That is what Gayle mentioned, in fact you can assign more stack for your application (look at the compiler or editbin options in the manual, its /F for cl.exe and /STACK for editbin, I think), but I'd prefer the pointer way.
__________________
Quote:
Originally posted by Bloomers III
sex is dirty and for losers who can't masturbate properly
Pitchfork is offline   Reply With Quote
Unread 28 Jan 2003, 09:50   #5
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
That array goes on the stack?!
WTF?
I always thought the array memory was allocated, not put on a stack.

I got around it by making the array part of my class, thus allocating the memory compile-time.
This still strikes me as "odd" though.
Structural Integrity is offline   Reply With Quote
Unread 28 Jan 2003, 10:41   #6
Pitchfork
Tourist
 
Join Date: Jun 2001
Location: moon
Posts: 90
Pitchfork is an unknown quantity at this point
No, it is a local variable and that's why in the stack frame. If you want to have it on heap you have to allocate it with new or malloc.
__________________
Quote:
Originally posted by Bloomers III
sex is dirty and for losers who can't masturbate properly
Pitchfork is offline   Reply With Quote
Unread 28 Jan 2003, 18:08   #7
JetLinus
Friendly geek of GD :-/
 
JetLinus's Avatar
 
Join Date: Nov 2000
Location: On my metal roid
Posts: 923
JetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud of
lol that's why i prefer VBasic ^^
*ducksandrunsaway*
__________________
[»] Entropy increases! :-/
JetLinus is offline   Reply With Quote
Unread 28 Jan 2003, 19:45   #8
Cyp
∞+♪˛
 
Join Date: Nov 2000
Location: :uo!te]oŻ|
Posts: 428
Cyp is an unknown quantity at this point
Could also declare it as
static unsigned char terra[TERRAINSIZE*TERRAINSIZE];

Should save (don't know how much) time allocating memory... Might also save time when accessing the array, since the address doesn't move, but might not either. Probably depends on the sanity of the writers of the compiler's optimizer. Although it's probably not an important amount of time to a function called loadTerrain.

(Same as declaring it outside a function, except it's supposed to get reset to zero before the program starts. It shouldn't make the program a megabyte bigger, but it's written by Micro$oft, so can't be sure.)


But new and delete are probably fine. (Haven't actually used new and delete, I just use malloc and free, though. Don't know if there is a difference.)
__________________
Structural Integrity for Creator - since he'll probably make PA turn 3D.
Wikipedia forum
Note to self - Don't write Chinese letters with bold and italics...
<!--Last incarnation: Nov 2000-->
Cyp is offline   Reply With Quote
Unread 28 Jan 2003, 19:48   #9
Nodrog
Registered User
 
Join Date: Jun 2000
Posts: 8,476
Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Quote:
Originally posted by Cyp
But new and delete are probably fine. (Haven't actually used new and delete, I just use malloc and free, though. Don't know if there is a difference.)
As far as I know, the only difference is that new calls the constructor when allocating memory for classes. I cant imagine thered be any speed difference, but I could be wrong.
Nodrog is offline   Reply With Quote
Unread 28 Jan 2003, 23:18   #10
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
Quote:
Originally posted by Nodrog
As far as I know, the only difference is that new calls the constructor when allocating memory for classes. I cant imagine thered be any speed difference, but I could be wrong.
We had a thread about this a few months ago. I think we came to the assumption that new/delete carried a slight overhead but I cba to check again.
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
Gayle29uk is offline   Reply With Quote
Unread 29 Jan 2003, 07:00   #11
queball
Ball
 
queball's Avatar
 
Join Date: Oct 2001
Posts: 4,410
queball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so little
I don't remember that
queball is offline   Reply With Quote
Unread 29 Jan 2003, 08:14   #12
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
Was that that "dynamic 2D array" thread? I think it was.
Anyway, I WOULD use new in this case. It isn't a performance critical part. For performance critical parts I'd use a global/static array anyway. I now used an array declared in the class itself. Perhaps I find another use for it in a later stage, if not, I'll change it to a dynamically allocated array.
Structural Integrity is offline   Reply With Quote
Unread 31 Jan 2003, 14:26   #13
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
Quote:
Originally posted by Structural Integrity
Was that that "dynamic 2D array" thread? I think it was.
That's the one

On an only vaguely related note, not using the stack (as a habit) also makes you much less likely to introduce a script kiddie exploitable bug
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
Gayle29uk is offline   Reply With Quote
Reply



Forum Jump


All times are GMT +1. The time now is 23:28.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018