Jump to content
  • Advertisement
Sign in to follow this  
JimPrice

Memory management and smart pointers

This topic is 5455 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, I've been doing a fair bit of reading about memory management and smart pointers, and would like to ask a few questions of the esteemed audience (smarm, smarm). From what I've read, memory management looks to handle a few issues, such as: fragmentation and coalescing statistic generation - mean, max amount of memory usage allocation auditing - tracking memory blocks and making sure they are freed correctly Smart pointers often seem to be integrated into this structure, in that they handle managing their own associated memory (primarily a way of getting rid of worrying about when to delete them). For example, the Boost::shared_ptr explicitly says in its description : "Every occurence of the new keyword in the code should have the form shared_ptr<T> p(new Y) ... If you follow this guideline, it naturally follows that you will have no explicit deletes..." Most memory manager implementations I have seen rely on over-riding global new/delete (or object-specific new/delete). How easy then is it to implement a custom memory manager when you hand new/delete responsibilities over to a libray like boost (I believe there is a similar issue with some of the IO functions that handle their own memory acquisitions). So - the question boils down to this. How are people integrating these concepts in their own designs? Is there a way of using a library such as Boost with a self-written memory manager? If you want this functionality do you need to write the smart pointers yourself, so as to integrate them with your custom memory manager? Or is there an alternative way to meet these objectives? Thanks in advance for any help, Jim.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by JimPrice
Most memory manager implementations I have seen rely on over-riding global new/delete (or object-specific new/delete).


It's generally a bad idea to do so, since it does prevent other part of the code to, well, overload it for themselves. If you do have two library that try and overload the global new/delete operators,, you're in trouble. Object-specific versions are OK.

Quote:
How easy then is it to implement a custom memory manager when you hand new/delete responsibilities over to a libray like boost


boost::shared_ptr is not aware of any tricks you might have pulled with new and delete. It'll use whatever operator delete is associated with the type of the object it holds - or whatever destruction function you passed it. Most of Boost is implemented as C++ include files, and thus get compiled into your program using whatever altered new/delete you have.

Quote:
Is there a way of using a library such as Boost with a self-written memory manager?


I think it should work straight out of the box.

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!