Imagine a vector of 2d points in image. You transform them in vector
3d points based on some computation.
Then you filter the 3d points you're not interested in. Then you go
back to the vector of 2d points and filter the one you removed from
the previous step. Imagine that I have a bunch of those
transformations, you end up with several containers of several 2d and
3d points. Still you only want a subset of all of them. That's the
general idea.
So it sounds you have pairs and if the both points were packed into
same struct (lets say "transformation") then when you kick a
transformation (because of non-pleasant 3D point properties) out then
you get 2D point kicked out automatically as well. So you do not need
to construct a filter based on 3D points that you kick out and then
apply that filter to 2D points? Or does the filter depend on other
pairs?
Sure. However, isn't it always true that it is faster to remove
objects from a list than a vector ?
Depends on size. Removal from list involves deallocation. The thing is
i do not even care about it when i do not have working prototype with
real field data examples so i can measure and profile performance. The
things are simple to play around and switch once i have information.
Considering, I will probably go for a solution in which I iterate
through the points and remove them as I go, would'nt it always be
faster ??
If the filter means that major part of container will be thrown away
with single run then i would expect copying the remainder to other
vector and swapping to be faster than modifying a list. That does not
matter without context. Further, when it matters, then there is a
boost::intrusive::list that is *really* fast. OTOH it is more complex
to use than vector and you said that you do not want to use boost.
Yeah sometimes I need one container, sometimes I need another. But
most of the time, I don't need all of them at the same time.
So I don't think a packed representation of all the data in an object
is optimal.
OK. I am still confused, but if you say so.
Ok. Last question, is it faster to filter each of them independently,
or all of them together. I think that when you filter each
independently, you don't end up with lot of cache misses fetching data
from each vector, no ?
If you visit each one once anyway then cache probably makes no
difference. KHD suggested using boost zip_iterator for efficiency. I
would not care unless i had profile that shows that i should. When i
have reasons then i summon a hero who helps me down to avoiding
latency of L1 cache line splits, when i do not have such reasons then
i ignore it all entirely.
I can already hear a lot of people complaining that's context
dependent, subject to empirical thoughts, and probably a lot out of my
skills
Still, I'm here to learn, so I'm open to critics, thoughts
and advices ^^
You just imagine that what you write is *soft*ware. Avoid mental image
of carving it into rock. Be prepared to throw parts of it away and
write anew when needed. You lack reasons to do it one way or other
now. So you should care about expressive interface first. Simple to
read code is also simpler to modify. Only geniuses can write things
that are near perfect on first attempt.