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=-1.0 required=5.0 tests=BAYES_00,FORGED_HOTMAIL_RCVD2, FREEMAIL_FROM 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 Received: by 10.68.189.72 with SMTP id gg8mr14423543pbc.4.1328630356451; Tue, 07 Feb 2012 07:59:16 -0800 (PST) Path: lh20ni270971pbb.0!nntp.google.com!news1.google.com!postnews.google.com!x19g2000yqh.googlegroups.com!not-for-mail From: adacrypt Newsgroups: comp.lang.ada Subject: Re: Help needed - Upper Bound of an array - Question. Date: Tue, 7 Feb 2012 07:59:15 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <9203a648-af0d-45a1-87ba-67373435b391@k10g2000yqk.googlegroups.com> NNTP-Posting-Host: 109.155.140.236 Mime-Version: 1.0 X-Trace: posting.google.com 1328630356 16378 127.0.0.1 (7 Feb 2012 15:59:16 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 7 Feb 2012 15:59:16 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: x19g2000yqh.googlegroups.com; posting-host=109.155.140.236; posting-account=pmkN8QoAAAAtIhXRUfydb0SCISnwaeyg User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ARLUEHNKC X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; GTB7.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729),gzip(gfe) Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-02-07T07:59:15-08:00 List-Id: On Feb 7, 3:08=A0pm, Ludovic Brenta wrote: > adacrypt wrote on comp.lang.ada: > > > > > > > I am not an expert programmer in Ada but I have taught myself enough > > Ada-95 to be able to write some difficult cryptography programs that I > > post in another group. > > > My problem is this. =A0I need to test the frequency of the ciphertext > > which is sometimes a long string of large positive integers of 7 or 8 > > digits in magnitude and to do that I need an array that will > > accommodate up to 10,000,000 elements ideally. > > > I have already found out that I cannot go more than 500,000 elements > > in the array size. =A0My computer has 32-bit architecture. > > > What I need to know from some kind person is this - Is the array size > > a property of the Ada-95 language or the computer? > > > I need to know this before resorting to a 64-bit computer which might > > not solve the problem and be an expensive mistake. > > > Your help would be greatly appreciated. > > Both. > > The computer (and its operating system) limit the size of a single > object in memory and also the maximum combined sizes of all objects > you allocate. =A0On modern 32-bit operating systems, this limit is > usually 2, 3 or 4 gibibytes (1 gibibyte =3D 2**30 bytes) per process. > > However there is also a limit imposed by the compiler and linker: the > stack size. The compiler and linker emit code that will allocate a > stack for each thread. This stack will have a limited size, typically > 2 mebibytes (2 * 2**20 bytes) per thread. =A0If you declare Ada tasks, > you can tell the compiler how large the stack must be for each but you > must use linker options to control the size of the stack for the > environment task (the task where your main program executes). > > Your observation that 500_000 elements (presumably 32-bit integers) is > the maximum you can achieve suggests that you are allocating your > array on the stack of the environment task (500_000 * 32bits =3D 2 > million bytes, i.e. almost 2 mebibytes). =A0If you would allocate your > array from the heap, you would be able to use all your physical and > virtual memory. > > Stack allocation looks like: > > declare > =A0 =A0My_Array : array (1 .. 500_000) of Integer; -- 2_000_000 bytes on > the stack > begin > =A0 =A0... > end; > > Heap allocation looks like: > > declare > =A0 =A0type Big_Array is array (Positive range <>) of Integer; > =A0 =A0type Big_Array_Access is access Big_Array; > =A0 =A0procedure Free is > =A0 =A0 =A0new Ada.Uncheched_Deallocation (Big_Array, Big_Array_Access); > =A0 =A0My_Array : Big_Array_Access is new Big_Array (1 .. 10_000_000); > =A0 =A0-- 40_000_000 bytes on the heap > begin > =A0 =A0... > =A0 =A0Free (My_Array); -- optional, if your program just exits at this > point, the operating system will reclaim memory > end; > > Note that allocating such a large array from the heap presumes a > large, *contiguous* range of free addresses in your virtual address > space. =A0Such a range normally exists when your program starts but will > probably be fragmented into insufficiently large free ranges if you > allocate and deallocate lots of smaller objects. =A0So, you should > allocate your large array as early as possible in the execution of > your program. =A0Alternatively, you should consider replacing the array > with a rope (seehttp://en.wikipedia.org/wiki/Rope_%28computer_science%29)= . > > HTH > > -- > Ludovic Brenta.- Hide quoted text - > > - Show quoted text - 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