local ffi = require 'ffi'
local psapi = ffi.load("Psapi.dll")
ffi.cdef[[
typedef unsigned long DWORD;
typedef unsigned long SIZE_T;
typedef struct _PROCESS_MEMORY_COUNTERS_EX {
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;
SIZE_T PrivateUsage;
} PROCESS_MEMORY_COUNTERS_EX, *PPROCESS_MEMORY_COUNTERS_EX;
void* __stdcall GetCurrentProcess(void);
int __stdcall GetProcessMemoryInfo(void* Process, void* ppsmemCounters, DWORD cb);
]]
local function GetCurrentMemoryUsage()
local memInfo = ffi.new("PROCESS_MEMORY_COUNTERS_EX")
local success = psapi.GetProcessMemoryInfo(ffi.C.GetCurrentProcess(), memInfo, ffi.sizeof("PROCESS_MEMORY_COUNTERS_EX"))
if not success then return nil end
return memInfo.PrivateUsage
end