Visual C++: stack overflow

Started by
12 comments, last by Structural 21 years, 2 months ago
quote:Original post by Paradigm Shifter
You do only have 1 copy of static locals, and C does support recursion.

I said 1 static copy, not 1 copy of a static. I may not have explained it very well, but if you understand there''s a big difference. In many languages that don''t support recursion (like old Fortran, not sure about more recent Fortrans) all local variables are static. As far as I can tell, there''s not really any other major reason to have a stack for local data other than recursion. Speed is not an issue here, as statics are just as fast as a stack. However, a stack is the most efficient storage when recursion is needed (that I can think of, my knowledge here is not bullet-proof).
Advertisement
ALL data, unless specifically allocated by new/malloc, is allocated on the stack (unless it''s global).

Most of the time, the pointers you use to access heap memory are allocated on the stack.
daerid@gmail.com
quote:Original post by Thrump
Original post by Paradigm Shifter
You do only have 1 copy of static locals, and C does support recursion.


Thrump said…
I said 1 static copy, not 1 copy of a static. I may not have explained it very well, but if you understand there's a big difference. In many languages that don't support recursion (like old Fortran, not sure about more recent Fortrans) all local variables are static. As far as I can tell, there's not really any other major reason to have a stack for local data other than recursion. Speed is not an issue here, as statics are just as fast as a stack. However, a stack is the most efficient storage when recursion is needed (that I can think of, my knowledge here is not bullet-proof).

I reply…
I misread your meaning, sorry. Isn't it daft to make all locals static in a language not supporting recursion though, you'd need to pre-allocate storage for all locals in all functions before the program would run?

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

[edited by - Paradigm Shifter on January 29, 2003 6:15:38 AM]
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
quote:Original post by daerid
ALL data, unless specifically allocated by new/malloc, is allocated on the stack (unless it's global).

Most of the time, the pointers you use to access heap memory are allocated on the stack.


I would advice to use windows own memory managers over new/malloc since windows memory managers can guarantee contigous memory where new/malloc cannot. For those who don't know what this means, it means that there is a performance penalty when using non contigous memory. Memory fragmentation is a real issue just as fragmented harddrives are. I cannot speak for other OS but I would assume that there are similar opportunities for optimization.


____________________________________________________________
Try RealityRift at www.planetrift.com
Feel free to comment, object, laugh at or agree to this. I won't engage in flaming because of what I have said. I could be wrong or right but the ideas are mine.



[edited by - MichaelT on January 31, 2003 1:35:59 AM]
No no no no! :)

This topic is closed to new replies.

Advertisement