Jump to content
  • Advertisement
Sign in to follow this  
Smit

Memory Management

This topic is 4587 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've never written a memory manager before and was wanting to give it a go but I don't know where to start. I had a few questions I was thinking about so I thought I'd post them here to get a better idea of things. 1. What type of memeory management is better for graphics/games applications? 2. I've seen the "heapsize" option in the Doom Engine, what technique does this use? 3. I've seen things like Smart Pointers etc. Are these part of a memory manager system? 4. I looked around for some articles but I couldn't really find any apart from superpigs engine articles (I've forgotten the name of them :/). Anyone have any interesting links on the subject? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
1. There's no right answer for everything. Sometimes certain approaches make more sense than others. Most non-trivial programs use more than one memory management model; it is not uncommon to have garbage collected languages implement high-level logic (like AI, game rules, etc.), for instance. Pooling is also very common.

2. No idea, sorry.

3. No. Smart pointers are a different concept entirely. Check out this article for a good overview of what they are for. Something that does have connections with memory management is STL allocators.

Share this post


Link to post
Share on other sites
You should probably start with what exactly you mean by memory manager.

Assuming you mean the typical definition of a custom malloc/new/free/delete if you can tell us why you think you need one at all instead of just using the built in one then we could give you better advise.

Share this post


Link to post
Share on other sites
Does anyone have any interesting links about doing this in C++? Everything I find on google is talking about normal new/delete or pascal :/

Share this post


Link to post
Share on other sites
Hey bud,

What you are typically looking to do here is overload new and delete and by redirecting the calls from these to your memory manager, you allocate from 1 large pool. Managing this manually.

1) In the memory manager class allocate a large pool like 1MB or something.
2) Put a header at the top of the memory, a struct. The idea is that you have a 16 byte header for each allocation. The structure of this header is typically:

4 bytes - size
4 bytes - next
4 bytes - previous
4 bytes - used

So you make one big 'allocation' inside that large chunk of memory you allocated by whackin this header at the top. For every allocation that comes from the overloaded new you find a header that heads a block of memory that is of suitable size. You add another header somewhere in this block for the new allocation and link the headers together.

You will end up with a linked list of allocation headers inside this big pool tha t you can traverse and merge etc.

Without sounding arrogant, but since i seem to be one of the very few on here to have written one of these, feel free to PM me or whatever instead. Your choice [grin]!

Hope that helps you get started,

Dave

Share this post


Link to post
Share on other sites
Lets say that I want everything to go through my memory manager. How do I get global static varibles to go through it? You could say make your allocator a global static, but there is no guarantee the order of what will be initialized first. And what allocates memory for the allocator?

Share this post


Link to post
Share on other sites
Quote:
Original post by Dave
Hey bud,

What you are typically looking to do here is overload new and delete and by redirecting the calls from these to your memory manager, you allocate from 1 large pool. Managing this manually.

1) In the memory manager class allocate a large pool like 1MB or something.
2) Put a header at the top of the memory, a struct. The idea is that you have a 16 byte header for each allocation. The structure of this header is typically:

4 bytes - size
4 bytes - next
4 bytes - previous
4 bytes - used

So you make one big 'allocation' inside that large chunk of memory you allocated by whackin this header at the top. For every allocation that comes from the overloaded new you find a header that heads a block of memory that is of suitable size. You add another header somewhere in this block for the new allocation and link the headers together.

You will end up with a linked list of allocation headers inside this big pool tha t you can traverse and merge etc.

Without sounding arrogant, but since i seem to be one of the very few on here to have written one of these, feel free to PM me or whatever instead. Your choice [grin]!

Hope that helps you get started,

Dave


Write up an article and submit it. Show off ;-)

Share this post


Link to post
Share on other sites
Look into the Slab Allocator. For the class of allocations it deals with, it's vastly more efficient than almost anything else; constant time allocation with an extremely low memory overhead (for the ideal case of allocating 4 byte ints, a 0.02 byte overhead per int).

Share this post


Link to post
Share on other sites
Spose i could write an article. I wrote the first part and submitted it and i got no reply or confirmation.

Dave

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!