comp.lang.ada
 help / color / mirror / Atom feed
From: Dr Adrian Wrigley <amtw@linuxchip.demon.co.uk>
Subject: Problems with large records (GNAT) [continued]
Date: Wed, 28 Feb 2001 02:44:12 -0800
Date: 2001-02-28T02:44:12-08:00	[thread overview]
Message-ID: <3A9CD67C.9B15C417@linuxchip.demon.co.uk> (raw)

Hi all!

You might remember a while back I had a problem with 'Size failing
on large types, using GNAT (3.12p Intel Linux (Red Hat 6.2)).
I never managed to solve that problem, and made do with keeping
all my records under 256MB (!).

This time, I have come across another manifestation of the problem,
which appears rather strange.  The locations for different
elements in a record are the same.  In the example code below,
the elements First and Last are stored in the same place.
(you can verify this using 'Access on the two elements).

I wish to use large records mapped into memory using the "mmap" call,
and obtain fast, random access to all the elements.  Subsequent runs
of the program can use the same data.  This is an order of magnitude
faster (sometimes two) than non-mmap solutions I tried.

I'm wary of rewriting the code significantly, because the same problem
may occur in the new code.  Maybe some linked structure could do it,
but then it would always need to be loaded in the same place.

Any ideas/comments?  Does this example work with other compilers on
32-bit architectures?

How can I work out how much storage to allocate, when 'Size and
'Max_Size_In_Storage_Elements can't handle it?

In this example, the code generates the wrong answer silently.
I dont like that...
-----------
with Text_IO;
with Interfaces.C;

procedure Dum is

   Size : Integer := 256*1024*1024 - 1;

   type Big_T is array (1 .. Size) of Float;

   type Item_T is record
      First : Float;
      Item  : Big_T;
      Last  : Float;
   end record;

   type Item_A is access all Item_T;

   function Malloc (Size : Interfaces.C.Size_t) return Item_A;
   pragma Import (C, Malloc, "malloc");

   X : Item_A;

begin

   X := Malloc (Interfaces.C.Size_T (Size * Float'Size + 2*Float'Size)); -- Hmmmm

   X.First := 3.14159;
   X.Last  := 2.71828;

   Text_IO.Put_Line ("First is " & Float'Image (X.First) &
                     " last is " & Float'Image (X.Last));

end Dum;
----------
$ gnatmake dum
$ dum
First is  2.71828E+00 last is  2.71828E+00
$
----------
Dr Adrian Wrigley



             reply	other threads:[~2001-02-28 10:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-02-28 10:44 Dr Adrian Wrigley [this message]
2001-02-28  3:13 ` Problems with large records (GNAT) [continued] Robert A Duff
2001-02-28 12:09   ` Dr Adrian Wrigley
2001-02-28  9:51     ` Florian Weimer
2001-02-28 18:35 ` Laurent Guerby
2001-03-01  8:17   ` Dr Adrian Wrigley
2001-03-01  1:58     ` Robert A Duff
2001-03-01 22:18       ` Dr Adrian Wrigley
2001-03-01 17:02         ` Robert A Duff
2001-03-01  7:00     ` tmoran
2001-03-01 21:52       ` Dr Adrian Wrigley
2001-03-01 19:32         ` tmoran
2001-03-01 19:38     ` Laurent Guerby
2001-03-02 20:32 ` Randy Brukardt
2001-03-07  2:15 ` Dr Adrian Wrigley
replies disabled

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