comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: Allocation questions
Date: Thu, 28 May 2009 15:00:12 +0200
Date: 2009-05-28T15:00:13+02:00	[thread overview]
Message-ID: <4a1e8add$0$30233$9b4e6d93@newsspool1.arcor-online.net> (raw)
In-Reply-To: <96a89bf4-4968-45fb-aa5b-4a47f2e06045@f19g2000yqo.googlegroups.com>

Ludovic Brenta schrieb:
> xavier grave:
>>> Or you could use a discriminant:
>>>    type Samples (No_Of_Samples : Natural := 0) is
>>>       record
>>>          S : array (1 .. No_Of_Samples) of Sample;
>>>       end record;
>> My two cents about variant discriminant : IMHO one should avoid to
>> declare No_Of_Samples as Natural and with a default value, because as
>> far as I remember some compilers will book for S (1 .. Natural'Last) of
>> Sample which can be a lot...
>>
>> May be some compiler guru can confirm or infirm this ?
> 
> I confirm this with GNAT even though I'm no guru. Well spotted,
> Xavier.

Using GNAT and -fstack-check, this will stem towards the
stack limit (Dummy just declares Samples records of
increasing No_Of_Samples):

with Ada.Text_IO;

procedure GNAT_Varrec is

   type Sample is new Float range 0.0 .. 1.0;
   type Run is array (Natural range <>) of Sample;

   type Samples (No_Of_Samples : Natural := 0) is
      record
         S : Run (1 .. No_Of_Samples);
      end record;

   procedure Dummy (N: Natural) is
      Scratch: Samples(No_Of_Samples => N);
   begin
      if N in Scratch.S'Range then
         Scratch.S(N) := 0.5;
      end if;
   end Dummy;

   K : Natural;

   package Text_IO renames Ada.Text_IO;
begin
   K := 0;
   while K < Natural'Last loop
      Text_IO.Put_Line("Size is " &
	Natural'Image(K * Sample'Size / 8) & " octets");
      Text_IO.Flush;
      Dummy(K);
      K := K + 4096;
   end loop;
end GNAT_Varrec;



  reply	other threads:[~2009-05-28 13:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-28  9:46 Allocation questions Olivier Scalbert
2009-05-28 10:02 ` Martin
2009-05-28 11:55   ` xavier grave
2009-05-28 12:19     ` Ludovic Brenta
2009-05-28 13:00       ` Georg Bauhaus [this message]
2009-05-28 23:13       ` Robert A Duff
2009-05-28 10:05 ` Dmitry A. Kazakov
2009-05-28 10:40   ` Martin
2009-05-28 12:32     ` Olivier Scalbert
2009-05-28 13:39       ` Martin
2009-05-28 13:57         ` Olivier Scalbert
2009-05-28 14:51         ` Adam Beneschan
2009-05-28 17:58           ` Randy Brukardt
2009-05-28 14:04       ` Dmitry A. Kazakov
2009-05-28 16:59 ` Jeffrey R. Carter
2009-05-28 17:26   ` Olivier Scalbert
replies disabled

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