comp.lang.ada
 help / color / mirror / Atom feed
From: "Alex R. Mosteo" <devnull@mailinator.com>
Subject: Re: exception access violation
Date: Wed, 15 Nov 2006 14:32:11 +0100
Date: 2006-11-15T14:32:11+01:00	[thread overview]
Message-ID: <4s0j3hFtng3pU1@mid.individual.net> (raw)
In-Reply-To: 1163584330.6500.6.camel@localhost.localdomain

Georg Bauhaus wrote:

> Why is using the heap + controlled for larger data structures
> more portable than using the stack? I know that GNAT needs to
> be talked into providing sufficient space on the stack.
> You might be that running into this kind of stack trouble only
> when you port from another compiler to GNAT?

I have no experiences out of GNAT, that be said first.

In past times, I had to deal with implicit limits in Linux/ld (I seem to
remember it was 2MB. This has changed with kernels and is no longer an
issue). Because of this, porting from Windows to Linux was somewhat painful
because problems not arising in Windows did arise in Linux (even using the
usual linker stack options, so I had to dig for even more obscure
switches). Other languages don't exploit so much the stack, so it is more
difficult to find experiences in the area from other developers.

Other point that may be relevant: by default, gnat doesn't release memory
historically claimed by stacks, contrarily to heap-allocated one. Couple
this with lots of tasks or recursivity and quickly memory can start to be
an issue. (I'm not sure if this is linux 2.6 default behavior or gnat
management of secondary stacks, couldn't locate it in the docs).

Finally is the trap I always fall for: "This is small enough to be in the
stack". And then it grows, and then it starts to be a problem, or some
recursive algorithm can't recurse enough, and you end changing it or having
humongous stacks or reworking algorithms.

Of course, in realtime environments you'll prefer to know your memory needs
from the start.

> Should the decision whether some object lives on the heap or on
> the stack be based on compilers' support for dynamically sized
> local data structures?

As long as compilers are not perfect, I suppose it is at least an extra
factor to consider. Also, I'd not limit it only to dynamically sized data.

I've been bitten several times by stack-related problems when using GNAT,
that's all I wanted to transmit (hence the 'in my experience' remark). If
you don't have desires to learn about system internals, GNAT
primary/secondary stacks and so... use the heap, luke ;)

It is worrysome that I'm saying all this, because I find much more
comfortable using the stack than any heap management.



  reply	other threads:[~2006-11-15 13:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-13 19:31 exception access violation Jade
2006-11-13 21:35 ` Georg Bauhaus
2006-11-14  9:09 ` Alex R. Mosteo
2006-11-14 19:34   ` Jade
2006-11-15  9:58     ` Alex R. Mosteo
2006-11-15  9:52       ` Georg Bauhaus
2006-11-15 13:32         ` Alex R. Mosteo [this message]
2006-11-15 23:43         ` Kevin K
  -- strict thread matches above, loose matches on Subject: below --
2009-05-18 16:05 Exception_Access_Violation mhamel_98
2009-05-18 16:14 ` Exception_Access_Violation John B. Matthews
2009-05-19  7:23   ` Exception_Access_Violation Alex R. Mosteo
2009-05-20 15:30     ` Exception_Access_Violation mhamel_98
2009-05-22 14:34       ` Exception_Access_Violation Björn Persson
2009-05-22 15:17         ` Exception_Access_Violation Niklas Holsti
2009-05-22 16:38       ` Exception_Access_Violation Adam Beneschan
2001-12-07 12:41 exception access violation Cousins, Jeff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox