From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1ff542cf207f32ca X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.226.10 with SMTP id ro10mr14817830pbc.6.1328640999791; Tue, 07 Feb 2012 10:56:39 -0800 (PST) Path: lh20ni271437pbb.0!nntp.google.com!news1.google.com!goblin1!goblin2!goblin.stu.neva.ru!news.teledata-fn.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Tue, 07 Feb 2012 19:56:38 +0100 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Help needed - Upper Bound of an array - Question. References: <9203a648-af0d-45a1-87ba-67373435b391@k10g2000yqk.googlegroups.com> In-Reply-To: Message-ID: <4f3173e6$0$6563$9b4e6d93@newsspool4.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 07 Feb 2012 19:56:38 CET NNTP-Posting-Host: 00826065.newsspool4.arcor-online.net X-Trace: DXC=mU8D`3>7SaZV0Pe9PRnbJ\4IUKZLh>_cHTX3j]dGjG^:A;FYT X-Complaints-To: usenet-abuse@arcor.de Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Date: 2012-02-07T19:56:38+01:00 List-Id: On 07.02.12 16:59, adacrypt wrote: > On Feb 7, 3:08 pm, Ludovic Brenta 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