Sign in to follow this  
mokaschitta

Custom Memory Allocators in ResourceManager?

Recommended Posts

Hi, I am currently working on my first little Rendering Engine which is alot of fun. I bough the book "Game Engine Architecture" by Jason Gregory which seems to be really good especially when it comes to more advanced topics in engine design. Anyways one thing he talks about alot are custom memory allocators like stack and pool allocators. For now my Resource manager just creates new objects with the c++ standard allocators like new and malloc (mostly "new") and then I save the Pointers in an STL vector in the ResourceManager. I am working on a Mac and I am still pretty much at the beginning so I was wondering if its worth the trouble to implement my own memory managment classes? As far as I understand the book it is especially useful if you are developing for consoles or systems that dont have much RAM or lack OS features to defragment the RAM automatically. Does anyone have experience on a MAC or PC if its worth or maybe even necessary to allocate memory using custom allocators? Thanks

Share this post


Link to post
Share on other sites
I would say that you probably don't need to worry about it yet. It's fairly easy to bolt them in later on on a class-by-class basis[1] when and if you find you need them. One way to help you do this is to try and minimise the number of places you call "new" and "delete" on objects.




[1] Many classes will not need this because there will be few instances.

Share this post


Link to post
Share on other sites
Agreed with Katie. For the time being, don't worry about custom memory allocators. At this point you should be more concerned with putting together a good rendering engine and hey, there's a ton to learn just on that front :)

When you're comfortable with the rendering engine itself, then you should move on to / look into other topics like memory management (which has a more general application).

By the way, to clarify, custom memory allocators are not only useful for platforms with tight memory constraints. It can also be used to gain a significant performance boost. Standard new is expensive since a free memory block has to be searched for, fragmented if necessary, and returned. A very easy way to bring a game to a crawl is to do thousands of new/deletes every frame. Pool allocators are nice because your memory usage is known up front and, depending on implementation, can be quite speedy (compared to standard new/delete). Anyway, point is to not dismiss custom memory allocators as being only appropriate for "limited" platforms :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this