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,FREEMAIL_FROM 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-7-bit Path: g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Sat, 17 May 2008 09:16:52 -0500 From: "Steve" Newsgroups: comp.lang.ada References: Subject: Re: Question about arrays and no. of elements Date: Sat, 17 May 2008 07:20:17 -0700 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-RFC2646: Format=Flowed; Original Message-ID: X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 24.20.111.206 X-Trace: sv3-14KDJJdGHLsi4aa3IUTDqeBCx+y6CCRD7otJC4H+zFyXRUC8OnmrHZcZpC1Ex5wF+25ErIvuxQ+AWJP!olbQyVGWVA6key1YUIaRtLwNs4rUyr0s9YaWhYmv2zaJBycanzQsUZgwCSFbZlENdDw7gy+aSy3E!FA+MTTZqtJmG7g9TpEqm5PLhRDLqcA== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.39 Xref: g2news1.google.com comp.lang.ada:156 Date: 2008-05-17T07:20:17-07:00 List-Id: wrote in message news:b60e9537-ab45-4856-99de-71127208813f@56g2000hsm.googlegroups.com... > 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)? Generally if you define an array with a million elements, most compiled languages (including Ada) will allocate memory for the array, which a waste of space, but not of time. After the array is allocated, references to elements are just memory references which are fast. Also note: Unlike some other programming languages, you may define the size of the array at run time, if you know the size of the array prior to use: type My_Array_Type is array( Positive range <> ) of Integer; ... num_elements : Positive; begin num_elements := GetNumElements; declare my_array_instance : My_Array_Type( 1 .. num_elements ); begin ... end; Regards Steve (The Duck)