PDA

View Full Version : Added new functions to EXE module



RobertoBianchi
02-04-2008, 13:12
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:


'---------------------------------------------------------------------------------
'---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()

Regards,
Roberto

Petr Schreiber
02-04-2008, 14:30
Thanks Roberto,

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


Thanks,
Petr

RobertoBianchi
02-04-2008, 16:06
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

Michael Hartlef
02-04-2008, 19:58
Thanks for the udate Roberto.

kryton9
03-04-2008, 01:58
Thanks for the update Roberto!