comp.lang.ada
 help / color / mirror / Atom feed
From: William Paul Berriss <W.P.Berriss@reading.ac.uk>
Subject: Re: Ada program's use of Stack and Heap
Date: 1997/04/20
Date: 1997-04-20T00:00:00+00:00	[thread overview]
Message-ID: <3359F8C2.791E@reading.ac.uk> (raw)
In-Reply-To: dewar.861363791@merv


Hi

I use Solaris 2.5 on a Sun SPARC 5 , and GNAT Ada95 v3.05.

I have got my programs to work now:  From what I have done,
I deduce the following (which may be only *almost* correct).

When I declare an array that has any runtime determined sizes,
then my program does NOT use the Stack  - I proved this because
if I make stack huge using Solaris 2.5 commands then my program
will work ONLY if I fix all the array sizes at compile time.
e.g. 
 type Hist_Array is array( Pixel, Pixel, Pixel ) of Natural;
 where type Pixel is defined as a Natural range 0..255.

BUT, if I decide on size at runtime then I get Segmentation Fault!
If I use *new* I also get Segmentation Fault, for such a 
64Megabyte array (even when I have limited stacksize to 2 gigabytes!).
(Same goes for my C++ version incidently.)

I can only presume that when I had a runtime size determined
array, my program it was using the Heap? not the Stack, and
hence threw up Segmentation Fault as the Heap was not big enough.
Definitely not the stack anyway.  And I cannot set the Heap
limit (to my knowledge) using Solaris UNIX commands (e.g. limit)


I have a number of programs that now work!

Incidently, one of them did not work at first, it declared
3 of these huge arrays.  
It siad Segemntation Fault again, despite big stack size
and fixed arrya size.
The only difference with this program
was that I had forgotton to use 

(others => (others => (others => 0 )));

when I declare the objects of this array type.

As soon as I made this one change everything worked!!!

When my program was *not* using *others*, 
it was as if the 64MB chunk of stack  I declared was
unusable because it was full of junk (not zeros).
When I came to use file_io.read data into this array it gave me
Segmentation Fault.  

(It was definitely the Read (i.e using
the declared but unitialise array ) that
threw up the error as I commented it out during a test.)

With the comments removed and using others 
the others cured it!
Odd?

Anyway, that was how I got *my* program to work OK, as they now do,
so it may be worth trying if you have the same problem?

Feel free to add to this theory? or improve upon it!

Will Berriss
------------

-- 

W P Berriss                 E-mail: W.P.Berriss@reading.ac.uk
Department of Engineering
The University of Reading
Whiteknights
Reading                     Tel:  0118 987 5123 
Berkshire                     (+44 118 987 5123 outside UK)
RG6 6AY    
England                     Fax:  0118 931 3327    

World Wide Web Home Page: 

http://www.elec.rdg.ac.uk/people/postgrads/will.html




      reply	other threads:[~1997-04-20  0:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <335358C5.43F8@reading.ac.uk>
1997-04-15  0:00 ` Segmentation Fault Robert Dewar
1997-04-18  0:00   ` Keith Thompson
1997-04-20  0:00     ` Robert Dewar
     [not found] ` <33538A67.709A@reading.ac.uk>
1997-04-15  0:00   ` Charlie Root
1997-04-16  0:00   ` Nicolas HUYNH
     [not found]     ` <3355DB39.3BAF@reading.ac.uk>
1997-04-19  0:00       ` I've Sussed my " Robert Dewar
1997-04-16  0:00 ` William Paul Berriss
1997-04-16  0:00   ` Stack and Heap sizes William Paul Berriss
1997-04-16  0:00     ` Samuel Tardieu
1997-04-16  0:00       ` Samuel Tardieu
1997-04-18  0:00     ` Robert Dewar
1997-04-20  0:00       ` William Paul Berriss [this message]
replies disabled

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