Jump to content
  • Advertisement
Sign in to follow this  
Eldritch

Memory questions

This topic is 2832 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 am quite confused about exactly how much memory my game is using. In my engine, I have overridden "new" so I can keep track of allocations. The size of an allocation is stored in my memory manager as "current memory". If the "current memory" (CUR) exceeds the "maximum memory usage" (MAX), the MAX value will be updated to match CUR. This is to know the memory peak.

CUR is also decreased with every deallocation.

Coursing through the game, the CUR value never exceeds 700 kB.

But here comes the weird part. If I look in the Task Manager, it says the game is using 32 MB of memory!! I cannot even begin to understand how that is possible, unless it also counts the memory used by the graphics card to store textures etc.

I am using Windows 7, and the game uses C++ and OpenGL.

Share this post


Link to post
Share on other sites
Advertisement
You're only overloading new in the places it's being used in your code, not in any other libraries you link against. So any memory allocated by OpenGL, the runtime, Windows API, etc., isn't going to show up. For the most part, that's all you should care about since it's all you have control over.

You can also use HeapWalk and specify the default heap. With this method you don't have to rely on any particular overload of new being called since everything eventually routes to the Windows memory management API. Unless a private heap is being used, which is somewhat rare, it will show up.

Share this post


Link to post
Share on other sites
Ah yes, that's true, but I do get STL allocations using "new" to be stored in my memory manager, so I guess that "new" being used in other libraries are as well. However, things might be using "malloc" instead.. which I am not registering. Thanks for the link, I'll look into that.

Share this post


Link to post
Share on other sites
Don't forget about 'new[]' as well. Any dynamic array allocations via 'new[]' and 'delete[]' won't be caught by your overridden 'new' and 'delete'.

Share this post


Link to post
Share on other sites
Quote:
Original post by Eldritch
Ah yes, that's true, but I do get STL allocations using "new" to be stored in my memory manager, so I guess that "new" being used in other libraries are as well. However, things might be using "malloc" instead.. which I am not registering. Thanks for the link, I'll look into that.

I should have been more specific, by "your code" I meant anything being compiled by you directly. Since a lot of the standard library is header-only you'll be compiling that code and hence getting your overloaded operators.

Share this post


Link to post
Share on other sites
Quote:

Coursing through the game, the CUR value never exceeds 700 kB.

But here comes the weird part. If I look in the Task Manager, it says the game is using 32 MB of memory!!

You also have to consider that TaskMan will show you the actual work-set size of your application. The OS manages your memory in pages (4KiB and up). To lower your working set's size, you have to free ALL the memory associated with a page of ram. If you allocated a std::list<int> of 1 million numbers and then erased every other number, you'd still very likely not change your working set. You have, however, freed up ram that can be reused to add more numbers to that list again.

Share this post


Link to post
Share on other sites
Quote:
Original post by KulSeran
Quote:

Coursing through the game, the CUR value never exceeds 700 kB.

But here comes the weird part. If I look in the Task Manager, it says the game is using 32 MB of memory!!

You also have to consider that TaskMan will show you the actual work-set size of your application. The OS manages your memory in pages (4KiB and up). To lower your working set's size, you have to free ALL the memory associated with a page of ram. If you allocated a std::list<int> of 1 million numbers and then erased every other number, you'd still very likely not change your working set. You have, however, freed up ram that can be reused to add more numbers to that list again.


Yeah, this is what I have come to suspect. So the app is not _really_ using 32 MB, it is just that it has an allocation "frame" of 32 MB?

Share this post


Link to post
Share on other sites
Quote:

So the app is not _really_ using 32 MB, it is just that it has an allocation "frame" of 32 MB?

More like it has 32MiB of 4KiB pages allocated, and each of those frames has atleast 1 byte used on them. This used memory totals an amount just over your 700KiB for reasons mentioned above (your exe size, loaded dlls, external library usage, etc.)

Virtual Memory Explained

Share this post


Link to post
Share on other sites
There is also a bug in the task manager in some versions of windows where it will not show memory which has been freed until you minimise your application and maximise it again. Try this and see? :-)

I can't find the official diagnosis of this bug, but here are a few people discussing its symptoms, it will happen with any program.

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!