Re: Ada.Containers.Vectors - querying multiple elements
- From: Duncan Sands <baldrick@xxxxxxx>
- Date: Tue, 26 Apr 2005 16:39:38 +0200
Hi Georg, thanks for replying.
> > procedure Query_Elements
> > (Container : in Vector;
> > First_Index : in Index_Type;
> > Last_Index : in Extended_Index;
> > Process : not null access procedure (Elements : in Element_Array));
>
>
> > It would be good to have for both
> > efficiency reasons and simple implementation of certain classes of algorithms.
> > In my case I have a "divide and conquer" recursive algorithm which while it
> > can be written using the current package, would be simpler to write if something
> > like Query_Elements existed.
>
> Couldn't you use Cursors,
>
> here: Cursor := find_or_something(container, ...);
> there: constant Cursor := find_or_something(container, ...);
>
> while here /= there loop
> ...
> next(here);
> end loop;
I'm particularly concerned about:
(1) efficiency - suppose (for example) I want to transmit the contents
of my vector down a socket. Then I would have to do an element-by-
element copy into a buffer (using code like you suggest), and then send
the buffer. The element-by-element copy is inefficient, and with a
procedure like Query_Elements above simply wouldn't (necessarily) be
needed. An element-by-element copy can't compete with memcpy (what
you'd probably get if you copied a slice directly, which would be
possible using Query_Elements), and certainly can't compete with no
copy at all. By the way, this is not a real example, it's just the
first thing that came to mind. In any case, it is a special case of
point (2):
(2) reuse of legacy code - I don't know about you, but I've a lot of
legacy code around that takes an array as a parameter. I mean code
that doesn't change the length of the array (or anything like that) -
code that just operates on the array in-place. Suppose I am using
a Vector, and want to have some legacy code operate on it, or on
part of it. Right now I would have to copy the appropriate part of
the Vector into a buffer, and pass that to the legacy code, and then
copy it back. Not very efficient - and not necessary if the Vectors
api was extended slightly.
Ciao,
D.
.
- Follow-Ups:
- Re: Ada.Containers.Vectors - querying multiple elements
- From: Matthew Heaney
- Re: Ada.Containers.Vectors - querying multiple elements
- References:
- Ada.Containers.Vectors - querying multiple elements
- From: Duncan Sands
- Re: Ada.Containers.Vectors - querying multiple elements
- From: Georg Bauhaus
- Ada.Containers.Vectors - querying multiple elements
- Prev by Date: Re: Syntax question: new with a constrained subtype indication
- Next by Date: Re: Ada.Containers.Vectors - querying multiple elements
- Previous by thread: Re: Ada.Containers.Vectors - querying multiple elements
- Next by thread: Re: Ada.Containers.Vectors - querying multiple elements
- Index(es):
Relevant Pages
|
|