Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import winlean
- type
- PROCESS_MEMORY_COUNTERS = object
- cb: int32
- PageFaultCount: int32
- PeakWorkingSetSize: uint
- WorkingSetSize: uint
- QuotaPeakPagedPoolUsage: uint
- QuotaPagedPoolUsage: uint
- QuotaPeakNonPagedPoolUsage: uint
- QuotaNonPagedPoolUsage: uint
- PagefileUsage: uint
- PeakPagefileUsage: uint
- # Only works on Windows - https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getprocessmemoryinfo
- proc getProcessMemoryInfo*(process: Handle, ppsmemCounters: var PROCESS_MEMORY_COUNTERS, cb: DWORD): WINBOOL {.stdcall, dynlib: "Psapi", importc: "GetProcessMemoryInfo".}
- proc fillSeq(y: int, x: var seq[seq[int8]]) =
- var
- w: seq[int8] = @[1i8, 2, 3, 4, 5, 6]
- z = 1
- while z <= y:
- add(x, w)
- inc(z)
- var
- c = getCurrentProcess()
- p: PROCESS_MEMORY_COUNTERS
- cap = 1310720
- ram1, ram2, ram3: uint
- echo "Ram usage by process before creating sequence"
- discard getProcessMemoryInfo(c, p, sizeof(p).DWORD)
- ram1 = p.WorkingSetSize
- echo ram1, " bytes\n"
- var x = newSeqOfCap[seq[int8]](cap) # sizeof(seq[seq[int8]]) = 8 -> 8 * 1310720 = 10485760
- echo "Ram usage by process after creating sequence with length 0 and capacity ", cap
- discard getProcessMemoryInfo(c, p, sizeof(p).DWORD)
- ram2 = p.WorkingSetSize
- echo ram2, " bytes\n"
- fillSeq(cap, x)
- echo "Ram usage by process after filling sequence"
- discard getProcessMemoryInfo(c, p, sizeof(p).DWORD)
- ram3 = p.WorkingSetSize
- echo ram3, " bytes\n"
- echo len(x), " len seq\n"
- echo "ram2 - ram1 = ", ram2 - ram1
- echo "ram3 - (ram1 + ram2) = ", ram3 - (ram1 + ram2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement