Jump to content
  • Advertisement
Sign in to follow this  
martin_bfg10k

Help with memory

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

How I can get the current memory used by my program? I'm programing in C++ with Mingw, and using SDL and OpenGL. In the program I allocate memory using "new", and some textures with OpenGL. For example: I want to know much how memory I have when the program start, how much memory I have after loading stuff, and how memory I have after delete all stuff and before finish the program. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Look up _CrtSetAllocHook in the MSDN. This function will let you set a callback that is called every time memory is allocated or deallocated. You can then write code using this info to track memory usage.

Share this post


Link to post
Share on other sites
All I can think of is to overload the new operator and to add the ammout of memory newed to a global memory used variable. Same thing when loading textures etc.

Share this post


Link to post
Share on other sites
Quote:
Original post by tmck2
Look up _CrtSetAllocHook in the MSDN. This function will let you set a callback that is called every time memory is allocated or deallocated. You can then write code using this info to track memory usage.


Well, but I don not use windows API, I'm trying to keep the program system idependent.

Share this post


Link to post
Share on other sites
Quote:
Original post by martin_bfg10k
Quote:
Original post by tmck2
Look up _CrtSetAllocHook in the MSDN. This function will let you set a callback that is called every time memory is allocated or deallocated. You can then write code using this info to track memory usage.


Well, but I don not use windows API, I'm trying to keep the program system idependent.


Exactly the same effect can be had by overloading the new and delete operators, and I think you could make that platform independant.

Share this post


Link to post
Share on other sites
Overloading new and delete?
Hmm, my programming skill are too bad yet, I don't know how to overload that operators :(
I'll read some C++ book, thanks for the reply.

Share this post


Link to post
Share on other sites
The easiest way I know of the code it into your game is to simply overload the global new and delete operators. There are of course some downsides to this; for example, you'd have no control over what is and is not tracked, and certain performance critical areas might suffer slightly. There are of course remedies for these, but they require a little bit more than merely overloading an operator.

BTW, one option is to merely look under the Memory Usage header under the Processes tab in the Task Manager (Ctrl+Alt+Del). I do not, however, know how accurate that is. If you don't know how to overload the global operators yet, you could at least give this a try.

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!