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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f31af493775a063b X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news1.google.com!postnews.google.com!34g2000hsf.googlegroups.com!not-for-mail From: Ken Thomas Newsgroups: comp.lang.ada Subject: Re: Question about arrays and no. of elements Date: Fri, 16 May 2008 02:50:55 -0700 (PDT) Organization: http://groups.google.com Message-ID: <2fce0b4f-f86a-46cc-989d-ee247834a7cc@34g2000hsf.googlegroups.com> References: NNTP-Posting-Host: 152.78.70.10 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1210931456 15310 127.0.0.1 (16 May 2008 09:50:56 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 16 May 2008 09:50:56 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 34g2000hsf.googlegroups.com; posting-host=152.78.70.10; posting-account=B_SmUwoAAAArT7-avjstloPG8dLOABck User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.2),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:95 Date: 2008-05-16T02:50:55-07:00 List-Id: On May 15, 4:19=A0pm, amal.alpho...@gmail.com wrote: > If I define an array with say a million elements, and I only put data > in 10 of them, is it actually a waste of space/time with the array or > does Ada only create elements when there is data to put in (so it is > efficient)? It will be a waste of space because you may limit the size of problem you can solve with your resources. It may be a waste of time if you perform operations on the whole array such as scaling. You have only defined 10 elements and given default values to the remaining 10^6 - 10 elements. Why not use a more suitable data structure such as a Map (Ada.Containers.Ordered_Maps)? I have used these to handle large sparse matrices that cannot be stored as dense arrays. I have not found any significant degradation of runtime performance and I don't think you will for such a small map. Ken