Skip to main content
gamedev.net
🔒 Locked

Memory Manager

Started by starfleetrp 3 replies 1.1k views
Original Post
starfleetrp
starfleetrp
I am looking for a good article on how I could impliment some memory managment for my game. From what I understand calling new and delete are very expensive for games, since those calls are used all the time. What I am looking for is a way to allocate a certain size of memory (1MB) or so at a time and fill it with data. I think you know what I mean by this and would be greatful for your oppinions on the subject or if you could to point me to a good article. [Edited by - starfleetrp on February 22, 2007 5:40:45 PM]
CTar
CTar
Quote:
What I am looking for is a way to allocate a certain size of memory (1MB) or so at a time and fill it with data.

That wouldn't help you, at least not the straightforward implementation. The implementers of new and delete are very skilled and have probably done something which is very close to optimal for the general case. The only way you're going to improve performance is if you know something about the allocations. One of the most common and effective techniques is to use memory pools.

Quote:
From what I understand calling new and delete are very expensive for games, since those calls are used all the time.

They should be used very rarely in games as well as other applications required a decent performance. If you plan to do any allocations frequently, then make sure to re-use memory. Don't allocate new memory in your main loop, just mark it as unused, if you don't then you will most likely encounter heavy fragmentation.

If you want to know more use this as a starting point. Follow the links to other article and make sure to search for the different techniques mentioned. Wikipedia doesn't really explain the techniques very deeply and lack articles for some of the techniques, but it helps you figure out what to search for. I have heard about people having success using buddy memory allocation, so that might be a good algorithm to compare other algorithms you try against.

Just remember the cheapest memory to allocate, is the one you don't allocate. Try to minimize the amount of allocation.
starfleetrp
starfleetrp
Sorry, I forgot the term that I was trying to define. I was trying to refer to a memory pool (I think thats the term) and allocate 1 - 100 MB (depending on preferences) at a time. So what I was really looking for was a link to memory pooling (sorry the mis-understanding). I will look into the links that you have posted.

Edit: Maybe I still have the terms wrong. What I want to do is allocate lets say 20 MBs at a time and fill up the space with a bunch of little objects (1 kb or bigger, since new and delete gets expensive after 1000's of calls)

CTar
CTar
Quote:
Original post by starfleetrp
Sorry, I forgot the term that I was trying to define. I was trying to refer to a memory pool and allocate 1 - 100 MB (depending on preferences) at a time. So what I was really looking for was a link to memory pooling (sorry the mis-understanding). I will look into the links that you have posted.


Boost have a decent explanation both of some general concepts and memory pools (simple segregated storage). Wikipedia one the other hand has a decent explanation which only deals with memory pools, and in a little more general terms. Both are great reading, though I have found that the Boost one is a little hard to read.

To basic idea is that you know the exact size of a number of allocations, which means you avoid fragmentation and can do a number of optimization like allocating many at a time.

The most important thing to do is make sure you understand what fragmentation is and why it's so bad.

Reading all this stuff and really understanding it may take some time, but it will really help you.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.