Reputation:
I know this might be an oversimplification - but I need to know the amount of free memory I could allocate in my program. It's a windows mobile project (c++) and it seems like I might have a memory leak hiding somewhere. Calling a function which returns the remaining size (or remaining chunks) of heap storage I could access would be perfect. Is there some way to traverse the available chunks of memory the operator new uses? Or a built-in WINAPI (or winmobile) function that does it?
Upvotes: 1
Views: 3362
Reputation: 514
Have a look at the heap state reporting functions:
http://msdn.microsoft.com/en-us/library/wc28wkas.aspx
First, include crtdbg:
#include <crtdbg.h>
then in your code:
_CrtMemState ms;
_CrtMemCheckpoint(&ms);
_CrtMemDumpStatistics(&ms);
this will output like so to the debug output window:
0 bytes in 0 Free Blocks.
56596 bytes in 2056 Normal Blocks.
17895 bytes in 83 CRT Blocks.
0 bytes in 0 Ignore Blocks.
0 bytes in 0 Client Blocks.
Largest number used: 74491 bytes.
Total allocations: 240054 bytes.
The default heap reserved space is 1MB, this can be adjusted in the Project Properties, Configuration Properties, Linker, System, "Heap Reserve Size" (VS 2010)
You might also want to look at _CrtSetDbgFlag http://msdn.microsoft.com/en-us/library/5at7yxcs(v=VS.100).aspx
Upvotes: 0
Reputation: 32685
Check out GlobalMemoryStatus. It will provide the amount of free physical memory. Note that older Windows CE enforce 32MB per process limit (Windows CE 6.0 lifts this limit).
Upvotes: 1
Reputation: 300797
Have you checked out The CLRProfiler for the .Net Compact Framework?
It's part of the Power Toys for .NET Compact Framework 3.5 download.
Getting Started Video Tutorial: How Do I: Use the CLR Profiler to Detect Finalization Problems On My Device?
Upvotes: 0