comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: Help needed - Upper Bound of an array - Question.
Date: Tue, 07 Feb 2012 19:56:38 +0100
Date: 2012-02-07T19:56:38+01:00	[thread overview]
Message-ID: <4f3173e6$0$6563$9b4e6d93@newsspool4.arcor-online.net> (raw)
In-Reply-To: <d0f24231-9160-4bbd-8286-6d219b8eb296@x19g2000yqh.googlegroups.com>

On 07.02.12 16:59, adacrypt wrote:
> On Feb 7, 3:08 pm, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote:

>> Heap allocation looks like:
>>
>> declare
>>    type Big_Array is array (Positive range <>) of Integer;
>>    type Big_Array_Access is access Big_Array;
>>    procedure Free is
>>      new Ada.Uncheched_Deallocation (Big_Array, Big_Array_Access);
>>    My_Array : Big_Array_Access is new Big_Array (1 .. 10_000_000);
>>    -- 40_000_000 bytes on the heap
>> begin
>>    ...
>>    Free (My_Array); -- optional, if your program just exits at this
>> point, the operating system will reclaim memory
>> end;

> 
> Many thanks to everyone - your'e a bit over my head technically but I
> get the gist of it from each one of you.
> 
> This is my declaration.
> 
>  SUBTYPE Index_30 IS Integer RANGE -500000 .. 500000;
>   TYPE I_CoefficientsNumArray IS ARRAY(Index_30) OF Integer;
>   I_Num : I_CoefficientsNumArray;
>   -- counts the occurences of the j coefficients of the ciphertext.
> 
> Question : can I use your 'big array' declaration procedure in Ada-95
> just as you have typed here ? that would be great - will it work just
> by replacing the present declaration with this? do I type in as a
> straight crib just like that, regards - adacrypt


Yes, also in Ada 83. I'd also follow Gaultier's suggestions.
(Note that resorting to pointers is necessary only if you use
a compiler + OS that cannot handle somewhat larger array sizes
in the environment task ("main program"), even when they are
just fine in tasks' storage).


Another boon to your program might be in Ada's fundamental
types: you can express your knowledge about the integers
("7 or 8 digits in magnitude") as a type, something like

  type Ints_in_the_Set is range 0 .. 87_456_321;

replacing the limits with whatever you think they should be,
of course, and choosing a suitable name.  This has several effects:

- the program no longer depends on implementation defined
  type Integer

- you, your readers, and the compiler will know what values to
  expect in all objects of type Ints_in_the_Set; this is not
  the case with Integer

- you can even adjust the type's size (in bits) as you see
  fit; when your program is compiled on a 64bit platform
  you might still specify a 'Size of 32 bits, which could
  save some cache memory




  parent reply	other threads:[~2012-02-07 18:56 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-07 14:41 Help needed - Upper Bound of an array - Question adacrypt
2012-02-07 15:00 ` Yannick Duchêne (Hibou57)
2012-02-07 15:04 ` Mark Lorenzen
2012-02-07 15:08 ` Ludovic Brenta
2012-02-07 15:27   ` Yannick Duchêne (Hibou57)
2012-02-07 15:59   ` adacrypt
2012-02-07 16:13     ` Gautier write-only
2012-02-07 17:30     ` Jeffrey Carter
2012-02-07 19:51       ` tmoran
2012-02-09  3:31         ` Randy Brukardt
2012-02-07 18:22     ` Ludovic Brenta
2012-02-07 20:42       ` adacrypt
2012-02-07 18:56     ` Georg Bauhaus [this message]
2012-02-07 21:22     ` Robert A Duff
2012-02-07 15:33 ` Álex R. Mosteo
2012-02-07 22:08 ` Jerry
replies disabled

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