#75825 - 2003-07-12 11:42 PM
Memory() Testing
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
After seeing the post about the MemorySize Function limit, it reminded me of an old batch file we used to use to determine memory. Converting it was somewhat of a journey, but I think I have done it... Anyone care to see if it works for memory over 2 gigs, or just see what results it give you?
break on memory()
function memory() dim $hexdmp, $hex, $counter, $hexvals, $memkey, $vals $memkey="HKEY_LOCAL_MACHINE\hardware\resourcemap\system resources\physical memory" $hexdmp=readvalue($memkey,".Translated") for $start = 1 to len($hexdmp) step 8 $hex="" for $counter = 0 to 7 step 2 $hex=substr($hexdmp,$start + $counter,2)+$hex next if $hexvals="" $hexvals=$hex else $hexvals=$hexvals + "|" + $hex endif next $vals=split($hexvals,"|")
for $counter= 8 to ubound($vals) step 4 $nul=execute("$$memory=0.0 + $$memory + &"+$vals[$counter]+"/1024") next $memory=int(($memory +648)/1024) endfunction
[ 13. July 2003, 07:18: Message edited by: Al_Po ]
|
|
Top
|
|
|
|
#75828 - 2003-07-13 12:15 AM
Re: Memory() Testing
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
Lonk,
quote: 0.0+"&$hex_val"
I may need a hex tuturial to understand how to change this...
1. Why the quotes around the variable? 2. What's the "&" for?
|
|
Top
|
|
|
|
#75830 - 2003-07-13 02:05 AM
Re: Memory() Testing
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
much to my surprise... and it took me quite a bit of tinkering to get to work... it appears to work without the hextodec functions... Thanks Jooel
I modified the code at the top of the post... Anyone willing to try it? [ 13. July 2003, 16:14: Message edited by: Al_Po ]
|
|
Top
|
|
|
|
#75831 - 2003-07-13 02:09 AM
Re: Memory() Testing
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11628
Loc: CA
|
Well,
I did try with the previous Hex conversion code but the answer was WAY off. The answer on 512MB was 16
; MemoryCheckByRegistry.kix
break on
$=setoption("WrapAtEOL","on")
? memory()
function memory(optional $remotepc)
dim $hexdmp, $hex, $counter, $hexvals, $memkey, $vals
if $remotepc=""
$remotepc='\\'+ @wksta
else
if not left($remotepc,2)="\\"
$remotepc='\\' + $remotepc
endif
endif
$memkey="\HKEY_LOCAL_MACHINE\hardware\resourcemap\system resources\physical memory"
$hexdmp=readvalue($remotepc + $memkey,".Translated")
for $start = 1 to len($hexdmp) step 8
$hex=""
for $counter = 0 to 7 step 2
$hex=substr($hexdmp,$start + $counter,2)+$hex
next
if $hexvals=""
$hexvals=$hex
else
$hexvals=$hexvals + "|" + $hex
endif
next
$vals=split($hexvals,"|")
for $counter= 8 to 16 step 4
$memory=$memory + hextodec($vals[$counter])/1024
next
$memory=($memory +648)/1024
endfunction
Function HexToDec($Hex)
; Convert Hex to decimal
; If the hex number is <= 7FFFFFFF the funtion returns an Integer
; If the hex number is > 7FFFFFFF the funtion returns the string representation of the integer value
; by use of the UDF: HexToDecStr()
$HexArr = "0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"," "
If $Hex > "7FFFFFFF" ; Will result in overflow, convert to "integer string" instead
$HexToDec = HexToDecStr($Hex)
Return
EndIf
$HexToDec = 0
$Fac = 1
For $L = Len($Hex) To 1 Step -1
$Ch = SubStr($Hex, $L, 1)
$nb = 0
While $Ch <> $HexArr[$nb] And $nb < 16
$nb = $nb + 1
Loop
If $nb = 16 ; Error in hex-string, contains non-valid characters
$HexToDec = 0
Return
EndIf
$HexToDec = $HexToDec + $nb * $Fac
$Fac = $Fac * 16
Next
EndFunction
Function HexToDecStr($Hex)
; Convert Hex-number to stringrepresentation af integer value
; Using UDF's:
; HexToBinStr()
; StrAdd()
; StrMult2()
$BinStr = HexToBinStr($Hex) ; Convert Hex to binary string
$BinVal = "1" ; Decimal stringvalue for first Binary digit
$HexToDecStr = "0"
For $L = Len($BinStr) To 1 Step -1
$Cif = SubStr($BinStr, $L, 1)
If $Cif = "1" ; "Add decimal stringvalues for Binary digits"
$HexToDecStr = StrAdd($HexToDecStr, $BinVal)
EndIf
$BinVal = StrMult2($BinVal) ; Create decimal stringvalue for next binary digit
Next
EndFunction
Function HexToBinStr($Hex)
; Convert Hex-number to binary string
$HexArr = "0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"," "
$BinArr = "0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"
$HexToBinStr = ""
For $L = Len($Hex) To 1 Step -1
$Ch = SubStr($Hex, $L, 1)
$nb = 0
While $Ch <> $HexArr[$nb] And $nb < 16
$nb = $nb + 1
Loop
If $nb = 16 ; Error in hex-string, contains non-valid characters
$HexToBinStr = "0"
Return
EndIf
$HexToBinStr = $BinArr[$nb] + $HexToBinStr
Next
While SubStr($HexToBinStr, 1, 1) = "0"
$HexToBinStr = SubStr($HexToBinStr, 2, Len($HexToBinStr) - 1)
Loop
EndFunction
Function StrAdd($Str1, $Str2)
; Add Strings, treat as integers
$StrAdd = ""
$Carry = 0
While Len($Str1) < Len($Str2)
$Str1 = "0" + $Str1
Loop
While Len($Str2) < Len($Str1)
$Str2 = "0" + $Str2
Loop
For $L = Len($Str1) To 1 Step -1
$Cif1 = Val(SubStr($Str1, $L, 1))
$Cif2 = Val(SubStr($Str2, $L, 1))
$CifSum = $Cif1 + $Cif2 + $Carry
$CifSumStr = "" + $CifSum
$StrAdd = SubStr($CifSumStr, Len($CifSumStr), 1) + $StrAdd
If Len($CifSumStr) > 1
$Carry = Val(SubStr($CifSumStr, 1, 1))
Else
$Carry = 0
EndIf
Next
If $Carry
$StrAdd = "" + $Carry + $StrAdd
EndIf
EndFunction
Function StrMult2($MultStr)
; Mutiply string by 2, treat as integer
$StrMult2 = ""
$Carry = 0
For $L = Len($MultStr) To 1 Step -1
$CifVal = Val(SubStr($MultStr, $L, 1)) * 2 + $Carry
$CifStr = "" + $CifVal
$StrMult2 = SubStr($CifStr, Len($CifStr), 1) + $StrMult2
If Len($CifStr) > 1
$Carry = 1
Else
$Carry = 0
EndIf
Next
If $Carry
$StrMult2 = "1" + $StrMult2
EndIf
EndFunction
|
|
|
Top
|
|
|
|
#75832 - 2003-07-13 02:10 AM
Re: Memory() Testing
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11628
Loc: CA
|
Tried your new code as well on a 512MB system and the answer still came out to be 16
|
|
Top
|
|
|
|
#75841 - 2003-07-15 02:40 PM
Re: Memory() Testing
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Jooel/Al,
I know that Jooel is great at KiXGolf or shaving bytes off of code..
Why not start here with KiXtart 4.02 or better?
HKLM is the same as - HKEY_LOCAL_MACHINE
TTFN,
Kent
|
|
Top
|
|
|
|
#75843 - 2003-07-15 04:13 PM
Re: Memory() Testing
|
Richie19Rich77
Seasoned Scripter
   
Registered: 2002-08-16
Posts: 624
Loc: London, England
|
I have tested on a 4GB server, and here are the results.
quote: R:\Kix\Tools>kix32 r:\test -415.82421875
R:\Kix\Tools>
Using Kix32 4.21
Rich
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 1198 anonymous users online.
|
|
|