Code:
/*
typedef struct _PROCESS_MEMORY_COUNTERS {
DWORD cb;
DWORD PageFaultCount;
SIZE_T PeakWorkingSetSize;
SIZE_T WorkingSetSize;
SIZE_T QuotaPeakPagedPoolUsage;
SIZE_T QuotaPagedPoolUsage;
SIZE_T QuotaPeakNonPagedPoolUsage;
SIZE_T QuotaNonPagedPoolUsage;
SIZE_T PagefileUsage;
SIZE_T PeakPagefileUsage;
} PROCESS_MEMORY_COUNTERS;
sizeof(PROCESS_MEMORY_COUNTERS) = 40
*/
// define a customized pointer type, size is 40
var ProcessMemoryCountersType = new DllParam(40, 1);
/*
BOOL GetProcessMemoryInfo(
HANDLE Process, // handle to process
PPROCESS_MEMORY_COUNTERS ppsmemCounters, // buffer
DWORD cb // size of buffer
);
*/
// register the GetProcessMemoryInfo function
var success = Dll.registerFunction("Psapi.dll",
"GetProcessMemoryInfo", "getPMemInfo", "stdcall",
"long", "long", ProcessMemoryCountersType, "long");
Dll.registerFunction("kernel32.dll", "GetCurrentProcess",
"getCurrentProcess", "cdecl", "long");
// handle the PROCESS_MEMORY_COUNTERS structur
function MemInfo()
{
var i;
this.value = new StringStream;
// fill the value
this.value.write(40);
for (i = 4; i < 40; i++) this.value.put(0);
function PageFaultCount()
{
this.value.getPos = 4;
return this.value.getLong();
}
function PeakWorkingSetSize()
{
this.value.getPos = 8;
return this.value.getLong();
}
function WorkingSetSize()
{
this.value.getPos = 12;
return this.value.getLong();
}
function QuotaPeakPagedPoolUsage()
{
this.value.getPos = 16;
return this.value.getLong();
}
function QuotaPagedPoolUsage()
{
this.value.getPos = 20;
return this.value.getLong();
}
function QuotaPeakNonPagedPoolUsage()
{
this.value.getPos = 24;
return this.value.getLong();
}
function QuotaNonPagedPoolUsage()
{
this.value.getPos = 28;
return this.value.getLong();
}
function PagefileUsage()
{
this.value.getPos = 32;
return this.value.getLong();
}
function PeakPagefileUsage()
{
this.value.getPos = 36;
return this.value.getLong();
}
}
function getMemInfo(memInfo)
{
if (getPMemInfo(getCurrentProcess(), memInfo, 40))
{
trace("Memory Usage: " + memInfo.WorkingSetSize());
}
}
if (success)
{
memInfo = new MemInfo();
Application.setInterval(getMemInfo, 1000, memInfo);
}