comp.lang.ada
 help / color / mirror / Atom feed
From: Erik Johannessen <erik.johannessen@kongsberg.com>
Subject: Re: gnat and heap size
Date: 26 Sep 2001 22:45:02 +0200
Date: 2001-09-26T22:45:02+02:00	[thread overview]
Message-ID: <vn2u1xp1y29.fsf_-_@sun356.fof.kog.no> (raw)
In-Reply-To: v%ls7.5903$ev2.9944@www.newsranger.com

Ted Dennison<dennison@telepath.com> writes:

> In article <Pine.NEB.4.31.0109260932510.24582-100000@behemoth.dreo.dnd.ca>,
> Claude Marinier says...
> >
> >The application is an electromagnetic simulation. Yes, we could use sparse
> >matrix techniques but part of the program requires a full matrix. Perhaps
> >we are hitting a low level limit (is that what Adrian is saying?).
> 
> If the small program you showed has the problem, then try the same
> thing with a small C program. If *it* has the problem too, then you
> have an OS issue that you should really take up with Solaris
> experts. If it doesn't have the problem, then at the least you can

There's no problem with malloc()'ing a 9000*9000*4 byte array on solaris,
provided you have that much vmem available.

In Claude's example if the array is declared as a constrained type
gnat will warn that a storage error will be raised at runtime.  As far
as I can tell this happens when the size of the array in bits is
larger than the largest positive value for a signed 32-bit integer.

When using new to allocate the array gnat will apparently not do any
checks for this. For the 9000x9000 array of float example it will
request a negative size from gnat_malloc/malloc.  An interesting
consequence of this is that if you continue to increase the size of
the array it will eventually get positive again, but the size will of
course not match the real size of the array.

The fun part here is that you can stay within the bounds you've
declared for the array, but access memory outside of the area
allocated for the array.  If you've got other data on the heap after
the array you'll get some interesting bugs. :)

The following code demonstrates the problem

with ada.text_io;

procedure matrix is
   type matrix is array ( integer range <> ) of integer;
   type matrix_a is access matrix;
   a: matrix_a;
   b: matrix_a;
begin
   a := New matrix( 1..152000000 );
   b := New matrix( 1..100 );

   for i in b'range loop
      b(i) := 0;
   end loop;

   a(17782318) := 42;

   for i in b'range loop
      if b(i) = 42 then
         ada.text_io.put_line("Found 42 at index " &
                              integer'image(i) & " in b");
      end if;
      b(i) := 0;
   end loop;

end matrix;

Compiled with gnat-3.14a1 on sparc-solaris2.6 I get:
> ./matrix
Found 42 at index  42 in b


A quick glance at the gnat rm/ug did not turn up any information on
this.  Also, I haven't checked if there is a compiler switch which
will turn on checks for this.

-Erik
-- 
/d{def}def/m{mul}d/a{add}d/q{repeat}d/y 1 d 300{/x 1 d 600{/c x 600 div 4 m 2
sub d/z y 300 div 2 m 1 sub d/r 0 d/i 0 d/t 0 d{t 1 le{/n r r m i i m sub c a
d/b 2 r m i m z a d/r n d/i b d r r m i i m a 16 gt{exit}if} {exit}ifelse/t t 
.01 a d}loop t setgray x y moveto 1 1 rlineto stroke/x x 1 a d}q /y y 1 a d}q



  reply	other threads:[~2001-09-26 20:45 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-25 18:29 gnat and heap size Claude Marinier
2001-09-25 20:46 ` Ted Dennison
2001-09-25 21:15   ` Marin David Condic
2001-09-25 21:49     ` Ted Dennison
2001-09-26 13:04       ` Marin David Condic
2001-09-26 13:39         ` Ted Dennison
2001-09-26 14:18           ` Larry Kilgallen
2001-09-26 14:27             ` Larry Kilgallen
2001-09-26 14:53             ` Marin David Condic
2001-09-26 17:21               ` Larry Kilgallen
2001-09-26 18:12                 ` Marin David Condic
2001-09-26 18:35               ` Marin David Condic
2001-09-27  7:20                 ` Martin Dowie
2001-09-26 21:16               ` Pascal Obry
2001-09-27 13:07                 ` Marin David Condic
2001-09-27 15:25                   ` Holographic memory (Was: gnat and heap size) Jacob Sparre Andersen
2001-09-27 16:26                   ` gnat and heap size Dale Pennington
2001-09-27 16:57                     ` Darren New
2001-09-27 16:58                     ` Marin David Condic
2001-09-27 19:19                     ` tmoran
2001-09-26 14:13         ` Larry Kilgallen
2001-09-27 10:39       ` Ole-Hjalmar Kristensen
2001-09-25 22:40   ` David Starner
2001-09-26  2:12   ` Robert Dewar
2001-09-26 13:36     ` Ted Dennison
2001-09-26  2:13   ` Robert Dewar
2001-09-26 13:29     ` Ted Dennison
2001-09-25 23:10 ` Dr Adrian Wrigley
2001-09-26  9:09   ` Lutz Donnerhacke
2001-09-26 13:58     ` The decline of programming civilization (was: gnat and heap size) Ted Dennison
2001-09-26 13:44   ` gnat and heap size Claude Marinier
2001-09-26 14:55     ` Ted Dennison
2001-09-26 20:45       ` Erik Johannessen [this message]
2001-09-27  6:12         ` Dr Adrian Wrigley
2001-09-27 18:23           ` erij
2001-09-27  9:02         ` Erik Johannessen
2001-09-27 13:27           ` Gerald Kasner
2001-09-27 17:48             ` erij
2001-09-27 14:11         ` Peter F. Gath
replies disabled

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