
typedef dword BOOL
typedef dword DWORD
typedef quad  DWORDLONG

typedef struct _MEMORYSTATUSEX {
  DWORD     dwLength;
  DWORD     dwMemoryLoad;
  DWORDLONG ullTotalPhys;
  DWORDLONG ullAvailPhys;
  DWORDLONG ullTotalPageFile;
  DWORDLONG ullAvailPageFile;
  DWORDLONG ullTotalVirtual;
  DWORDLONG ullAvailVirtual;
  DWORDLONG ullAvailExtendedVirtual;
} MEMORYSTATUSEX, *LPMEMORYSTATUSEX;


extern lib "kernel32.dll"

void Sleep(sys msecs)
BOOL GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer)

end extern

MEMORYSTATUSEX m
m.dwLength = sizeof m
GlobalMemoryStatusEx m
quad mi=m.ullAvailPhys

void AvailMem(quad*ma){GlobalMemoryStatusEx m : ma=m.ullAvailPhys}
void UsedMem(quad*ma){GlobalMemoryStatusEx m : ma=mi-m.ullAvailPhys}


TEST:
=====
string cr=chr(13,10)
quad ma1,ma2,ma3,ma4
sz=1e4 'bytes string
UsedMem ma1


function f1() as string
return space(sz)
end function

function f()
string s
string s1
sys    a
sys    i
s=space(sz)
s1=space(sz)
for i=1 to 1000
  '1
  'if s=space(sz)
  'end if
  '2
  'if space(sz)=s
  'end if
  '3
  's=space(sz)
  '4
  's=space(sz)+space(100)
  '5
  'if s=space(sz)+space(100)
  'end if
  '6
  'if space(sz)+space(100)=s
  'end if
  '7
  's=f1()
  '8
  's=f1()+f1()
  '9
  'if f1()<>f1()
  'end if
  '10
  'if f1()<>f1() then a=a
  '11
  'a=instr(s,s)
  '12
  'a=instr(s+s,s)
  '13
  'if a=instr(s+s,s) then a=a
  '14
  'string t=space(sz) 'DELIBERATE LEAKER
  '15
  'let t=space(sz) 'DELIBERATE LEAKER
  '16
  'if s+f1()<>s+f1() then a=a
  '17
  's=space(sz)+123
  '18
  's=f1()+123+space(sz)
  '19
  'if s=s then a=a
  'if s<>s then a=a
  'if s=42 then a=a
  'if s<>42 then a=a
  '20
  's=s+s1
  '21
  's+=s1
  '22
  's+=f1()
next
s=""
s1=""
UsedMem ma2
end function

f()
sleep 1000
UsedMem ma3

print ma1 cr ma2 cr ma3 '10MEG IF LEAKING
