Results 1 to 5 of 5

Thread: Added new functions to EXE module

  1. #1

    Added new functions to EXE module

    Hi,

    I've been added the EXE_PE_GetHeapReserve(), EXE_PE_GetHeapCommit(), EXE_PE_GetStackReserve() and EXE_PE_GetStackCommit functions to the EXE module.
    You'll find this update in the next ThinBasic release.
    Here is a test script:

    [code=thinbasic] '---------------------------------------------------------------------------------
    '---ThinBASIC needed modules
    '---------------------------------------------------------------------------------
    USES "LL"
    USES "EXE"
    USES "FILE"
    uses "Console"

    '---------------------------------------------------------------------------------
    '---Global variables
    '---------------------------------------------------------------------------------
    GLOBAL nFiles as long
    global nSkippedFiles as long
    GLOBAL sTime as string
    global geStackR as ext
    global geStackC as ext
    global geHeapR as ext
    global geHeapC as ext

    %MY_MAXPATH = 125
    %OFN_PATHMUSTEXIST = &H00000800
    %OFN_FILEMUSTEXIST = &H00001000

    SUB ProcessFile(lDir AS STRING, sFileMask as string)
    LOCAL Count AS LONG
    LOCAL FileName AS STRING
    LOCAL pList AS LONG
    LOCAL nItems AS LONG
    local eStackR as ext
    local eStackC as ext
    local eHeapR as ext
    local eHeapC as ext

    pList = DIR_LIST(lDir, sFileMask, %FILE_NORMAL OR %FILE_HIDDEN OR %FILE_SYSTEM OR %FILE_ADDPATH)
    nItems = LL_Count(pList)

    IF nItems > 0 THEN
    FOR Count = 1 TO nItems
    INCR nFiles
    FileName = LL_GetItem(pList, Count)
    eStackR = EXE_PE_GetStackReserve(FileName)
    ' Skip some unpleasant files
    if eStackR < 0 then
    incr nSkippedFiles
    else
    eStackC = EXE_PE_GetStackCommit(FileName)
    eHeapR = EXE_PE_GetHeapReserve(FileName)
    eHeapC = EXE_PE_GetHeapCommit(FileName)
    geStackR += eStackR
    geStackC += eStackC
    geHeapR += eHeapR
    geHeapC += eHeapC
    console_writeLine(Lset$(Filename, %MY_MAXPATH) & ":" & hex$(eStackR,6) & " " & hex$(eStackC, 6) & " " & hex$(eHeapR, 6) & " " & Hex$(eHeapC, 6))
    end if
    NEXT
    END IF

    END SUB

    FUNCTION ListDir(sDir AS STRING, sDirMask as string, sFileMask as string) AS LONG

    LOCAL Count AS LONG
    LOCAL Item AS STRING
    LOCAL pList AS LONG
    LOCAL nItems AS LONG
    LOCAL CurrentRow AS LONG

    LOCAL TFS AS QUAD

    pList = DIR_LIST(sDir, sDirMask, %FILE_Subdir OR %FILE_HIDDEN OR %FILE_ADDPATH)
    nItems = LL_Count(pList)

    IF nItems > 0 THEN
    FOR Count = 1 TO nItems
    Item = LL_GetItem(pList, Count)
    CurrentRow = nFiles
    TFS = ProcessFile(Item, sFileMask)
    INCR nFiles
    ListDir(Item, sDirMask, sFileMask)
    NEXT
    END IF

    END FUNCTION

    '-------------------------------------------------------------------------
    'Main Program
    '-------------------------------------------------------------------------
    sub Main()
    DIM T1 as long

    T1 = TIMER
    console_writeLine(Lset$(" FILENAME", 125) & " STACK HEAP")
    console_writeLine(string$(%MY_MAXPATH, " ") & " RESERVE COMMIT RESERVE COMMIT")
    ListDir("c:\windows\", "*.*", "*.EXE")
    sTime = FORMAT$(Timer - T1, "#0.00000")
    console_writeLine("TOTAL TIME (Secs): " & sTime)
    console_writeLine("FILE SCANNED: " & str$(nFiles))
    console_writeLine(Lset$("MEAN VALUES: ", %MY_MAXPATH) & ":" & hex$(geStackR/(nFiles - nSkippedFiles),6) & " " & hex$(geStackC/(nFiles - nSkippedFiles), 6) & " " & hex$(geHeapR/(nFiles - nSkippedFiles), 6) & " " & Hex$(geHeapC/(nFiles - nSkippedFiles), 6))
    end sub

    '-------------------------------------------------------------------------
    'Start
    '-------------------------------------------------------------------------
    CALL Main()[/code]

    Regards,
    Roberto
    http://www.thinbasic.com

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736

    Re: Added new functions to EXE module

    Thanks Roberto,

    what does heap reserve mean for example, is it some preallocated memory space when application starts up?


    Thanks,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3

    Re: Added new functions to EXE module

    Yes Petr, more precisely:

    SizeOfStackReserve is the amount of virtual memory to reserve for the initial thread's stack, however not all of this memory is committed but only the amount specified by the SizeOfStackCommit field. For example this field is what PB fills with the value specified after the #STACK metastatement.

    SizeOfStackCommit is the amount of memory initially committed for the initial thread's stack.

    SizeOfHeapReserve is the amount of virtual memory to reserve for the initial process heap. This heap's handle can be obtained by calling GetProcessHeap. Like as for the stack not all of this memory is committed but only the amount specified by the SizeOfHeapCommit field. Recently I had some problems with the process heap in ThinAir.

    SizeOfHeapCommit is the amount of memory initially committed in the process heap.

    Roberto
    http://www.thinbasic.com

  4. #4
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    58
    Posts
    3,299
    Rep Power
    348

    Re: Added new functions to EXE module

    Thanks for the udate Roberto.

  5. #5
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,865
    Rep Power
    405

    Re: Added new functions to EXE module

    Thanks for the update Roberto!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

Similar Threads

  1. Web site: added news module
    By ErosOlmi in forum Web and Forum
    Replies: 3
    Last Post: 09-09-2007, 11:03

Members who have read this thread: 1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •