LB Booster
« LBB (initial) memory usage »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:33am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: LBB (initial) memory usage  (Read 560 times)
Hans
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 31
xx 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
 
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx 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.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls