Note that there are some explanatory texts on larger screens.

plurals
  1. POC++: How are pointers themselves handled regarding memory management?
    text
    copied!<p>I have a fairly simple question; I have arrays which contain pointers to objects. I sometimes create mutated arrays from those arrays and only use them, let's say, within a method. Aftwards I don't need them. In this case I don't want the pointed data to be destroyed as I keep using the original Array. What I don't fully understand is what happens to the pointers ( not the data itself, but the pointers) that were created in my temporarily Array? How does Memory deal with them. As far as I know Pointers can only point to an address. You can't "delete" them.</p> <p>Anyone who can give me more insight? All this time I feel like I'm doing something wrong with memory.</p> <p>In this case list is my "bag", which is an object wrapper for an array implementation. However since it contains gabs between indexes I use getGapless to get a bag where the nullptr indexes are excluded.</p> <p>I delete my bag at the end, but it doesn't delete the actual content ( that is done with a different method ).</p> <p>So when do those pointers in my "players" bag go out of scope?</p> <pre><code>virtual void processEntities(artemis::ImmutableBag&lt;artemis::Entity*&gt;&amp; bag) { artemis::Bag&lt;artemis::Entity*&gt; * list = (artemis::Bag&lt;artemis::Entity*&gt;*)this-&gt;world-&gt;getGroupManager()-&gt;getEntities("HUMAN"); if(list == nullptr) return;//Kill function artemis::Bag&lt;artemis::Entity*&gt; * players = list-&gt;getGapless(); for(int i=0; i&lt;players-&gt;getCount(); i++) { for(int j=i+1; j &lt; players-&gt;getCount(); j++) { if(intersects(*players-&gt;get(i),*players-&gt;get(j))){ std::cout &lt;&lt; "Collide YEAH \n"; } } } delete players; } </code></pre>
 

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