comp.lang.ada
 help / color / mirror / Atom feed
From: Ken Thomas <kst@ecs.soton.ac.uk>
Subject: Re: Question about arrays and no. of elements
Date: Fri, 16 May 2008 02:50:55 -0700 (PDT)
Date: 2008-05-16T02:50:55-07:00	[thread overview]
Message-ID: <2fce0b4f-f86a-46cc-989d-ee247834a7cc@34g2000hsf.googlegroups.com> (raw)
In-Reply-To: b60e9537-ab45-4856-99de-71127208813f@56g2000hsm.googlegroups.com

On May 15, 4:19 pm, 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



  parent reply	other threads:[~2008-05-16  9:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-15 15:19 Question about arrays and no. of elements amal.alphonse
2008-05-15 16:30 ` gautier_niouzes
2008-05-15 16:50 ` anon
2008-05-15 17:52 ` Adam Beneschan
2008-05-16  9:50 ` Ken Thomas [this message]
2008-05-17 14:20 ` Steve
2008-05-17 16:32 ` Jacob Sparre Andersen
2008-05-17 17:37   ` Ludovic Brenta
replies disabled

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