Jump to content
  • Advertisement
Sign in to follow this  
elias4444

C++ Memory Management and Me

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

I guess I'm not a beginner to game development, but I really am a beginner at C++ (I've done everything in Java and LWJGL up until now). My main fear in switching over to C++ is dealing with the whole memory management paradigm. I'm worried that whatever engine I end up making will be riddled with memory leaks. So, my question is, what's a good way to deal with the constant creation and destruction of game objects in C++? Use "new" and "delete" for all objects? Create an object manager that takes this issue into account? Anyone have a good tutorial somewhere? Any help is appreciated!

Share this post


Link to post
Share on other sites
Advertisement
Understanding and making good use of the RAII idiom is the first step. Another is to use existing, well tested RAII wrappers such as those provided by the standard library (notably std::vector<> and std::string) along with boost (boost's smart pointer library). Using the other standard containers rather than rolling your own. When all else fails write your own RAII wrappers.

Don't be sucked into creating "manager" objects if you can avoid it. Each object should ideally be usable outside any external context, and if that is not possible then the other context should be minimised.

Don't dynamically objects if you can avoid it. Generally you should only be using new (and delete, but this is typically handled by your RAII wrapper object) when you are dealing with polymorphic objects. C++ is less reliant on polymorphism than Java, prefer object composition where possible.

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!