Re: Ada.Containers.Vectors - querying multiple elements



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.

.



Relevant Pages

  • Re: Why does rewind() ignore errors?
    ... These edits are almost mechanical in nature. ... its goal of requiring only edits to adapt legacy code to use the TR ... it might be vulnerable to buffer overruns, ... There are some libraries out there that make it easy to verify the ...
    (comp.std.c)
  • Re: Difficulty Reading in Constants
    ... | the .f file itself i.e. you modify the text file, compile and run. ... | I want is for the legacy code to be compiled as a .exe. ... Thus, in F77, you cannot size an array that way (there are some ...
    (comp.lang.fortran)
  • Re: Array of objects as array of POD
    ... Convert the class into a typedef. ... Convert all instances of point as an array to type Point. ... A typedef may be safer for legacy code, ... C++ Faq: http://www.parashift.com/c++-faq-lite ...
    (comp.lang.cpp)
  • Re: Ada.Containers.Vectors - querying multiple elements
    ... > Recursive algorithms on arrays that change their ... > Or are array parameters used for the side effect of passing ... That's why I've been mentioning legacy code: ... level abstraction built on low level building blocks, ...
    (comp.lang.ada)
  • Array of objects as array of POD
    ... While maintaining some legacy code I came across such a class ... This class doesn't have any virtual functions and is aligned by ... Also huge arrays of Points are passed as 3 * array of doubles to ... Any reference to the standard would be greatly appreciated. ...
    (comp.lang.cpp)