maximum number of variables?

Ian Lance Taylor ian@airs.com
Wed Aug 31 04:20:00 GMT 2005


Bob Rossi <bob@brasko.net> writes:

> On Tue, Aug 30, 2005 at 10:54:02PM +0100, Lexington Luthor wrote:
> 
> > I think for large arrays, its best to allocate them from the heap. Use 
> > malloc() or new (if using C++).
> 
> I've always been told that the heap and stack grow towards each other.
> If this is true, why would it be OK to create the item on the heap, vs
> on the stack? If it's not true, could someone simply explain how this
> works?

You are correct in theory.  In practice the heap and stack have
different limits, and the limit on the heap is much larger than the
stack (if running bash, compare ulimit -s and ulimit -v).  And if you
worry about portability, on some platforms allocating a large stack
frame will simply fail, and on some other platforms it will require
extra work to emit stack probes to tell the OS that you are
intentionally extending the stack rather than just referencing a
random memory address.

Ian



More information about the Gcc-help mailing list