开发者

How to get info on how much RAM does your app eat?

So I need it crossplatfom way, may be using boost, or at least for windows. So how to get i开发者_JS百科nfo on how much RAM does your app eat ?


For Windows, use the Task Manager; for Linux, use top. You're much better off having the OS tell you rather than trying to guess within your application.


Try getrusage() on *NIX and GetProcessMemoryInfo() on Windows.

http://www.opengroup.org/onlinepubs/009695399/functions/getrusage.html
http://msdn.microsoft.com/en-us/library/ms683219%28VS.85%29.aspx


On Windows with Visual Studio you can use CRT Debug Heap functions. _CrtMemDumpStatistics could be used to print useful stats. _CrtMemDumpAllObjectsSince lists all the objects allocated between checkpoints. There is more useful stuff like memory leak detection (_CrtDumpMemoryLeaks). It's also possible to take snapshots with _CrtMemCheckpoint and compare differences with _CrtMemDifference later on.

It's also possible to redefine new to get more detailed information with CRT debug functions.

#ifdef _DEBUG
#define new new(_CLIENT_BLOCK, __FILE__, __LINE__)
#endif

Note: This only tracks the CRT allocations. To get the entire process memory information you could use GetProcessMemoryInfo.


Personally I like to use http://valgrind.org/ to test the overall performance of my applications, VERY USEFUL FOR MEMORY LEAK DETECTION! If your looking for simple runtime info both Linux's TOP command and Window's task manager are very easy to use.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜