Note that there are some explanatory texts on larger screens.

plurals
  1. POC++:member reference or pointer?
    text
    copied!<p>I have a collection (currently <code>boost::ptr_vector</code>) 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:</p> <ol> <li><p>Passing a <code>boost::ptr_vector&lt;object&gt;&amp;</code> to the constructor of <code>Functor</code> and having a <code>boost::ptr_vector&lt;object&gt;&amp;</code> member in the Functor class</p></li> <li><p>Passing a <code>boost::ptr_vector&lt;object&gt;*</code> to the constructor of Functor and having a <code>boost::ptr_vector&lt;object&gt;*</code> member in the Functor class</p></li> <li><p>avoid the use of <code>boost::ptr_vector</code> and directly pass an array (<code>object*</code>) to the constructor</p></li> </ol> <p>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.</p> <p>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).</p> <p>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.</p> <p>Any advice is much appreciated</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload