Re: maximum number of variables?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Aug 30, 2005 at 09:19:19PM -0700, Ian Lance Taylor wrote:
> Bob Rossi <bob@xxxxxxxxxx> 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.

Thanks for the great explanation! Also, please correct me if I'm wrong.
Most likely if ulimit -s == ulimit -v, then it's possible that moving
the array from the stack to the heap would still cause the same problem.
However, if the limit's are different (stack being smaller), then moving
the array could be a successful choice. Does this sound correct to you?

Thanks,
Bob Rossi

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux