Jump to content
  • Advertisement
Sign in to follow this  
Silex

STL container that works like vector of pointers?

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

Hi, Is there an STL container class that works like a vector of pointers to avoid creating copies during sorting and re-arranging of the array? I suppose it's easy enough to just write vector<object*> and call delete on the objects manually, just wondering if there was somethign that encapsulated that functionality alreaedy... Thanks!

Share this post


Link to post
Share on other sites
Advertisement
And you can also use a container of smart pointers like boost::shared_ptr<> if boost::ptr_vector isn't quite right for your needs.

Share this post


Link to post
Share on other sites
Or you can store objects that handle destruction automatically (smart pointers, or other RAII objects) in your vector.

Share this post


Link to post
Share on other sites
If your goal is avoid creating copies, then the best solution is probably a container of pointers, but if your goal is both fast sorting and random access, then std::map might be the best compromise.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!