Jump to content
  • Advertisement
Sign in to follow this  
LilithAnn

Some std::help

This topic is 4387 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Please forgive me if this formatting is wrong. I've seen reference to using source tags/delimiters but I haven't yet found the documentation on it. I would appreciate a pointer to that if possible. AAR and regardless... I'm doing some reading in advance, as opposed to advanced reading, before diving into my project. Right now I'm trying to absorb the article on Enginuity. In it the author creates a static std::list of pointers to his objects. Each object, as it's created pushes its 'this' pointer onto the list and initializes a counter as to what number of processes are referencing it. My concern the operation of the garbage collection phase. In essence....
void IMMObject::CollectGarbage()
{
   for(std::list<IMMObject *>::iterator it=liveObjects.begin(); 
       it!=liveObjects.end(); )
   {
      IMMObject *ptr=(*it);
      ++it;
      if(ptr->refCount<=0)
      {
         liveObjects.remove(ptr);
         delete ptr;
      }
   }
}


The code I'm not grokking is 

    liveOjbects.remove(ptr);

If I'm reading this code correctly, ptr is a pointer to the object type, which is what comprises the elements of the std::list liveObjects.  Does the .remove function remove any elements that match the function argument by value?  Although this wouldn't be the case here, would it do it for all elements that have that value?

TIA,
Lilith

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by LilithAnn
The code I'm not grokking is

liveOjbects.remove(ptr);

If I'm reading this code correctly, ptr is a pointer to the object type, which is what comprises the elements of the std::list liveObjects. Does the .remove function remove any elements that match the function argument by value?

Yes. In fact the list member function remove is specialised version of the global algorithm remove.
Quote:
Although this wouldn't be the case here, would it do it for all elements that have that value?

Yes.

This is a useful reference on the SC++L, (actually the original STL, but most of it is still relevant and the bits that aren't are clearly marked as such). Or, if you have the resources and the desire for a paper reference I'd recommend The C++ Standard Library, A Tutorial and Reference by Nicolai M. Josuttis.

Finally, the instructions on [source] tags can be found in the GDNet Forums FAQ. Basically they operate just like html, so you need to close them!

Σnigma

Share this post


Link to post
Share on other sites
Thanks to both of you. The links have helped forstall my asking one more question about the iterator, its validity and what it actually is.

Lilith

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!