Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

psykr

STL iterators

This topic is 5305 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

Extending Enginuity''s memory manager, I''ve decided to give each IMMObject it''s own std::list iterator for faster removal. Instead of giving each object a "bIsStackAllocated" flag, I want to have the member iterators of stack objects point to a unique IMMObject::StackIterator. Is there any way for me to make sure that this iterator will not be used, i.e. create a "null iterator" the way a "null pointer" can be used? On destruction, instead of checking a flag to see if it''s stack-allocated, then the object would check its member iterator with a known iterator instead.

Share this post


Link to post
Share on other sites
Advertisement
Is this so that it will automatically remove itself from the container when its destructor is called?

Each object will keep a reference to the container and its own iterator. That seems like a large overhead for every object. If all your objects are in a container and you find one of them needs deleting you can remove it from the container and delete it. It doesn''t need to be hard coded into the object itself. It seems very inflexible. If you use a smart pointer such as boost.smart_ptr you can just remove it and it will automatically be deleted.

Share this post


Link to post
Share on other sites
No, it will flag itself to be removed, then the memory manager will remove it, then destroy the object, converting it back to raw memory. The whole idea behind my memory management system is that each object that wants to be managed will inherit from MMObject, and so I''ve got my own smart pointer class. I don''t want the objects to just delete themselves, I only need them to mark themselves. So I guess that smart_ptr would work, by my supplying a deleter that only marks it for removal, but I don''t want to work with boost because I''m afraid I''ll use it far too inefficiently.

Why would each object keep a reference to the container? Having an iterator is sufficient. I know that I can just search through the list, but why search twice when I will be looking for the iterator the first time anyway? (I haven''t tested it, so I may not even implement it at all.)

Share this post


Link to post
Share on other sites
quote:
Original post by psykr
but I don''t want to work with boost because I''m afraid I''ll use it far too inefficiently.


Sounds like a great opportunity to learn, IMNSHO

Share this post


Link to post
Share on other sites

  • 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!