public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bob Rossi <bob@brasko.net>
To: lexington.luthor@gmail.com, gcc-help@gcc.gnu.org
Subject: Re: maximum number of variables?
Date: Wed, 31 Aug 2005 11:19:00 -0000	[thread overview]
Message-ID: <20050831111914.GB5325@white> (raw)
In-Reply-To: <m364tmn3g8.fsf@gossamer.airs.com>

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

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

  parent reply	other threads:[~2005-08-31 11:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-30 21:01 Nicolas Ouellette
2005-08-30 21:08 ` Bob Rossi
2005-08-30 21:41   ` Nicolas Ouellette
2005-08-30 22:13     ` Lexington Luthor
2005-08-31  1:01       ` Bob Rossi
2005-08-31  4:20         ` Ian Lance Taylor
2005-08-31  9:13           ` Re[2]: " Miguel A. Nuñez
2005-08-31 11:17             ` Bob Rossi
2005-09-01  8:20               ` Re[2]: " Miguel A. Nuñez
2005-08-31 11:19           ` Bob Rossi [this message]
2005-08-30 23:01 ` corey taylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050831111914.GB5325@white \
    --to=bob@brasko.net \
    --cc=gcc-help@gcc.gnu.org \
    --cc=lexington.luthor@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).