Author |
Topic: LBB (initial) memory usage (Read 560 times) |
|
Hans
New Member
member is offline


Gender: 
Posts: 31
|
 |
Re: LBB (initial) memory usage
« Reply #4 on: Mar 20th, 2015, 10:29am » |
|
It has something to do whith the way you retreive the amount of memory used. I use the code below since long in a number of LB apps. In LBB the result is always 500, but the Taskmanager gives much lower amounts, more believeble. That's why I've now included an extra if statement for LBB. Because in LBB one has almost infinite memory, it is not high on my prioritylist but I will have to look for another way to retreive the amount of memory.
Hans
Code:FUNCTION GetUsedMemory(byref ErrorMsg$)
'=returns the memory used by the current process
'returns -1 if an error is encountered
'the error message is stored in the submitted variable
ErrorMsg$ = ""
struct ProcessMemoryCounters, _
cb as ulong,_
PageFaultCount as ulong,_
PeakWorkingSetSize as ulong,_
WorkingSetSize as ulong,_
QuotaPeakPagedPoolUsage as ulong,_
QuotaPagedPoolUsage as ulong,_
QuotaPeakNonPagedPoolUsage as ulong,_
QuotaNonPagedPoolUsage as ulong,_
PagefileUsage as ulong,_
PeakPagefileUsage as ulong
ProcessMemoryCounters.cb.struct = len(ProcessMemoryCounters.struct)
open "psapi.dll" for dll as #psapi
calldll #kernel32, "GetCurrentProcess",hProcess as ulong
cb = len(ProcessMemoryCounters.struct)
calldll #psapi, "GetProcessMemoryInfo",_
hProcess as ulong,_
ProcessMemoryCounters as struct,_
cb as ulong,_
result as long
if result then
GetUsedMemory = ProcessMemoryCounters.PagefileUsage.struct
else
call GetLastError ErrorMsg$
GetUsedMemory = -1
end if
close #psapi
UsedMemory = GetUsedMemory/1000000 'convert to MB
if instr(version$,"LBB")<>1 then
if UsedMemory>65 then notice "Memory nearly full: "+using("####",UsedMemory)
end if
END FUNCTION
SUB GetLastError byref Message$
calldll #kernel32, "GetLastError", ErrorCode as ulong
dwFlags = _FORMAT_MESSAGE_FROM_SYSTEM
nSize = 1024
lpBuffer$ = space$(nSize); chr$(0)
dwMessageID = ErrorCode
calldll #kernel32, "FormatMessageA", _
dwFlags as ulong, _
lpSource as ulong, _
dwMessageID as ulong, _
dwLanguageID as ulong, _
lpBuffer$ as ptr, _
nSize as ulong, _
Arguments as ulong, _
result as ulong
Message$ = left$(lpBuffer$, result)
END SUB
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: LBB (initial) memory usage
« Reply #5 on: Mar 20th, 2015, 12:21pm » |
|
on Mar 20th, 2015, 10:29am, Hans wrote:| It has something to do whith the way you retreive the amount of memory used. |
|
The problem is that both you and Anatoly are measuring the Commit Charge, which is the amount of memory a process has said it might use.
But this reserved address space does not actually use up real memory, until you create variables, arrays, structures, strings etc. to occupy it. In other words it doesn't reduce the memory available to other processes, which run in their own private address spaces.
This article has some interesting information. In particular read the section So what is “commit?”:
http://brandonlive.com/2010/02/21/measuring-memory-usage-in-windows-7/
Specifically it warns that if you disable your page file then Windows will reserve real memory rather than virtual memory, and then LBB really will gobble up 500 Mbytes of RAM!
Richard.
|
|
Logged
|
|
|
|
|