Note that there are some explanatory texts on larger screens.

plurals
  1. POReplacing raw pointers in vectors with std::shared_ptr
    primarykey
    data
    text
    <p>I have the following structure:</p> <pre><code>typedef Memory_managed_data_structure T_MYDATA; std::vector&lt;T_MYDATA *&gt; object_container; std::vector&lt;T_MYDATA *&gt; multiple_selection; T_MYDATA * simple_selection; </code></pre> <p>Edit: this may be very <strong>important</strong>: the Memory_managed_data_structure contains, among other things, a bitter, raw pointer to some other data.</p> <p>It aims to be a very simple representation of an original container of memory managed objects (object_container) and then a "multiple_selection" array (for selecting many objects in the range and doing various operations with them) and a "simple_selection" pointer (for doing these operations on a single object).</p> <p>The lifetime of all objects is managed by the object_container while multiple_selection and simple_selection just point to some of them. multiple_selection and simple_selection can be nullified as needed and only object_container objects can be deleted.</p> <p>The system works just fine but I am trying to get into shared_ptrs right now and would like to change the structure to something like:</p> <pre><code>typedef Memory_managed_data_structure T_MYDATA; std::vector&lt;std::shared_ptr&lt;T_MYDATA&gt; &gt; object_container; std::vector&lt;std::shared_ptr&lt;T_MYDATA&gt; &gt; multiple_selection; std::shared_ptr&lt;T_MYDATA&gt; simple_selection; </code></pre> <p>Again, the object container would be the "owner" and the rest would just point to them. My question is, would this scheme wreak havok in the application?. Is there something I should know before snowballing into these changes?. Are not shared_ptr the appropriate kind of pointer here?.</p> <p>I can somewhat guarantee that no object would exists in multiple_selection or simple_selection if it is not in object_container first. Of course, no delete is ever called in multiple_selection or simple_selection.</p> <p>Thanks for your time.</p> <p>Edit: Forgot to mention, never used any of these automated pointers before so I may be wildly confused about their uses. Any tips and rules of thumb will be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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