comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Efficiency and overhead: Ada.Containers.Vectors.vector versus array type
Date: Sat, 21 Jan 2012 12:11:31 -0700
Date: 2012-01-21T12:11:31-07:00	[thread overview]
Message-ID: <jff2l4$b0u$1@adenine.netfront.net> (raw)
In-Reply-To: <a011aaef-8ce5-4256-96e3-b2813dc101db@n6g2000vbz.googlegroups.com>

On 01/21/2012 11:19 AM, Ada BRL wrote:
>
> I need a "collection" of objects (every object has a lot of records
> like task objects, Gnat.Sockets and so on...);
> This collection is accessed several times during the execution.
> In the meantime I don't have to insert and delete any items during the
> execution, I just need to instantiate N object when the application
> starts and then the number of objects will remain the same throughout
> the execution.

This sounds perfect for an array. What is called a "vector" in the standard 
container library is an unbounded array. One uses an unbounded data structure 
when one doesn't know how large the structure will be until run time in such a 
way that one cannot declare a bounded structure; one uses a bounded structure 
(an array, in this case) in most other cases.

There's an additional reason you probably want an array rather than a vector: 
since your objects contain tasks, they are limited. You can't store limited 
objects in a vector, so you'll have to allocate them on the heap and store 
accesses to them in the vector. This introduces additional complexity to your 
code that would not appear when using an array. Also, since a vector is 
unbounded, it is also stored on the heap and accessed through an access value, 
making a vector involve double indirection.

Usually the syntax for dealing with an array is clearer than the equivalent 
using a vector (in current Ada; the next version of the standard will include 
changes to make them more equivalent).

-- 
Jeff Carter
"Run away! Run away!"
Monty Python and the Holy Grail
58

--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---



  parent reply	other threads:[~2012-01-21 19:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-21 18:19 Efficiency and overhead: Ada.Containers.Vectors.vector versus array type Ada BRL
2012-01-21 18:40 ` Simon Wright
2012-01-21 19:11 ` Jeffrey Carter [this message]
2012-01-22 15:05   ` Ada BRL
replies disabled

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