I have a collection (currently boost::ptr_vector
) of objects (lets call this vec) that needs to be passed to a few functors. I want all of the functors to have a reference/pointer to the same vec which is essentially a cache so that each functor has the same data cache. There are three ways that I can think of doing this:
Passing a
boost::ptr_vector<object>&
to the constructor ofFunctor
and having aboost::ptr_vector<object>&
member in the Functor classPassing a
boost::ptr_vector<object>*
to the constructor of Functor and having aboost::ptr_vector<object>*
member in the Functor classavoid the use of
boost::ptr_vector
and directly pass an array (object*
) to the constructor
I have tried to use method 3, but have been told constantly that I should use a vector instead of a raw pointer. So, I tried method 2 but this added latency to my program due to the extra level of indirection added by the pointer. I am using method 1 at the moment, however I may need to reassign the cache during the lifetime of the functor (as the data cache may change) so this may not be an appropriate alternative.
Which I don't fully understand. I assume somewhere along the way the functor is being copied (although these are all stored in a ptr_vector themselves).
Is method 3 the best for my case? method 2, is too slow (latency is very crucial), and as for method 1, I have been advised time and again to use vectors instead.
Any advice is much appreciated