comp.lang.ada
 help / color / mirror / Atom feed
* Efficiency and overhead: Ada.Containers.Vectors.vector versus array type
@ 2012-01-21 18:19 Ada BRL
  2012-01-21 18:40 ` Simon Wright
  2012-01-21 19:11 ` Jeffrey Carter
  0 siblings, 2 replies; 4+ messages in thread
From: Ada BRL @ 2012-01-21 18:19 UTC (permalink / raw)


Hello everyone!

I need some hints about Ada.Containers.Vectors.vector efficiency.

I'm developing a multithreaded real time application in Ada.

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.

Since I know how many object will be inside the collection I thought
to use, as the collection I need, the "array standard type".
In the meanwhile the Ada.Containers.Vectors.vector object is far more
practical, simple and has even more interesting and useful functions
like iterators and so on.

For this reason, since I don't have any experience in Ada, I ask you
all what can you suggest me to use.
If there is no such difference in efficiency/overhead between array
types and Ada.Containers.Vectors.vector I'll definitely use the
latter.

Thank you so much!



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Efficiency and overhead: Ada.Containers.Vectors.vector versus array type
  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
  1 sibling, 0 replies; 4+ messages in thread
From: Simon Wright @ 2012-01-21 18:40 UTC (permalink / raw)


Ada BRL <ada.brl.2011@gmail.com> writes:

> I need some hints about Ada.Containers.Vectors.vector efficiency.
>
> I'm developing a multithreaded real time application in Ada.
>
> 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.
>
> Since I know how many object will be inside the collection I thought
> to use, as the collection I need, the "array standard type".  In the
> meanwhile the Ada.Containers.Vectors.vector object is far more
> practical, simple and has even more interesting and useful functions
> like iterators and so on.
>
> For this reason, since I don't have any experience in Ada, I ask you
> all what can you suggest me to use.
> If there is no such difference in efficiency/overhead between array
> types and Ada.Containers.Vectors.vector I'll definitely use the
> latter.

It's bound to take longer to, for example, iterate over a Vector than to
loop over an array. The question is, how much longer? and is that
acceptable for your proposed usage?

I'd have thought the actual operations you want to do on your objects
would be independent of the storage mechanism, so maybe you could use
the Vectors first, do some measurements, and see if that will be
adequate.

I'd  start by something like creating an Indefinite_Vector of Strings,
populating it with say 1000 strings, and seeing how long it takes to
iterate over it. I'd expect it to be sub-microsecond per element, on a
modern processor (but I could be wrong!)

One thing to be wary of: an object with an embedded task will be
limited, which means you can't hold it directly in any of the standard
Containers; you'd have to hold access-to-object (or
access-to-object'Class if you have tagged types). This means you'll need
to do storage management yourself, perhaps using Ada.Finalization.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Efficiency and overhead: Ada.Containers.Vectors.vector versus array type
  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
  2012-01-22 15:05   ` Ada BRL
  1 sibling, 1 reply; 4+ messages in thread
From: Jeffrey Carter @ 2012-01-21 19:11 UTC (permalink / raw)


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 ---



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Efficiency and overhead: Ada.Containers.Vectors.vector versus array type
  2012-01-21 19:11 ` Jeffrey Carter
@ 2012-01-22 15:05   ` Ada BRL
  0 siblings, 0 replies; 4+ messages in thread
From: Ada BRL @ 2012-01-22 15:05 UTC (permalink / raw)


Thank you all for the interesting and useful suggestions!!!

I think I'll use the bounded arrays instead of vectors because, as you
said, this data structure fits more my purposes.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-01-22 15:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2012-01-22 15:05   ` Ada BRL

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