memory used by application

In Director there was a lingo command _system.freeBytes that would tell you how much free memory the system had.

I’m curious if there is a way in c++ of knowing how much memory the application itself is using. Just like looking in the running processes in windows & looking at memory usage.

Any thoughts most welcome,

this is the first google pass on that problem. this is a win32 solution I found. I think there are posix things that do the same thing, but didn’t come up with them right away.

I didn’t check it yet - just posting because it looks promising.

#include <Psapi.h>			// (need GetProcessMemoryInfo)  
void mem_info()  
	// From SDK docs:  
		The working set is the amount of memory physically mapped to  
		the process context at a given time. Memory in the paged pool  
		is system memory that can be transferred to the paging file on  
		disk (paged) when it is not being used. Memory in the nonpaged  
		pool is system memory that cannot be paged to disk as long as  
		the corresponding objects are allocated. The pagefile usage  
		represents how much memory is set aside for the process in the  
		system paging file. When memory usage is too high, the virtual  
		memory manager pages selected memory to disk. When a thread  
		needs a page that is not in memory, the memory manager reloads  
		it from the paging file.  
	// Thus, all we're really interested in is the PagefileUsage value.  
	pmc.cb = sizeof(pmc);  
	if (!GetProcessMemoryInfo(GetCurrentProcess(),&pmc,sizeof(pmc)))  
		return;		// (must be running on Win9x)  
	printf("\nCurrent PagefileUsage = %ld K   (peak: %ld K)\n\n",  

you will need to link against “Psapi.lib” which should be with the other windows libs (w/ whatever compiler you have)… if you google “GetProcessMemoryInfo GetCurrentProcess” you’ll see some other pages / code samples that might be helpful…

hth !

if you are developing on a mac and using XCode there’s this wonderful option to start the project using MallocDebug which makes it very easy to find memory leaks.
go to Run->Start with Performance Tool->Malloc Debug