Page 1 of 2 12>
Topic Options
#75825 - 2003-07-12 11:42 PM Memory() Testing
Allen Administrator Online   shocked
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($hexdmpstep 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 $counter8 to ubound($valsstep 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
#75826 - 2003-07-13 12:00 AM Re: Memory() Testing
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Did a quick test on a machine with 4G - got script errors. That system is running at least Kix 4.12, and might be 4.20.

I didn't have time to troubleshoot it, but the errors were in the Hex/Dec conversion UDFs.

I might be able to tinker more on Monday.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#75827 - 2003-07-13 12:03 AM Re: Memory() Testing
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I wonder.
where you need hextodec?
0.0+"&$hex_val"

should do it just fine.
_________________________
!

download KiXnet

Top
#75828 - 2003-07-13 12:15 AM Re: Memory() Testing
Allen Administrator Online   shocked
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... [Razz]

1. Why the quotes around the variable?
2. What's the "&" for?

Top
#75829 - 2003-07-13 12:24 AM Re: Memory() Testing
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
see the manual [Wink]
& says to kixtart that it's hex-value.
"0.0+" tells kixtart that the value should be translated to floating point thus it has no integer limitation.
_________________________
!

download KiXnet

Top
#75830 - 2003-07-13 02:05 AM Re: Memory() Testing
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
[Eek!] 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 Offline
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 [Confused]





; 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 Offline
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 [Confused] [Confused]
Top
#75833 - 2003-07-13 02:31 AM Re: Memory() Testing
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
it might be a problem in allen's other code...
as it seems.

allen, come up in MSN so we can shoot it quicker.
_________________________
!

download KiXnet

Top
#75834 - 2003-07-13 02:58 AM Re: Memory() Testing
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
doc, array out of bounds it says on your code.
_________________________
!

download KiXnet

Top
#75835 - 2003-07-13 03:07 AM Re: Memory() Testing
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
there must be something really wrong in that.
$vals ubound: 0
_________________________
!

download KiXnet

Top
#75836 - 2003-07-13 03:25 AM Re: Memory() Testing
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, not sure what the heck is going on with my kix.
using wkix32.exe ver4.20 it didn't read the registry at all!

but removing the \\@wksta\ part gives good results.

so, without any dependencies:
  $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=($memory +648)/1024
$memory ?
get $

_________________________
!

download KiXnet

Top
#75837 - 2003-07-13 07:03 AM Re: Memory() Testing
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Jooel... thanks for the ideas... I incorporated them into the above post and truncated the fraction so its back to good ole whole numbers. Sorry I missed the chat invitation... I do not have any of your IM usernames... I'll join the conversation sometime if you will send them to me (or since this is MSN, might your email address work?)

I will test the remote part when I get to work next week... and may or may not add it back.

DOC...did you ever get it to work. I am running Kix4.20 and I also have 512MB.

I'm curious how this will do with memory over 2 gigs....

Top
#75838 - 2003-07-13 08:00 AM Re: Memory() Testing
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Ok, now both Allen and Lonkeros code seems to work.

I'm not sure I have a 4GB system to check or not. Most are 2GB. I'll check my list and see if I have any 4GB systems and try it out.

Top
#75839 - 2003-07-14 03:42 AM Re: Memory() Testing
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
I'll try it Monday. Most of our production servers are 4 Gig. There's a couple of QA servers I can test it on.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#75840 - 2003-07-14 08:55 AM Re: Memory() Testing
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yep, email addy (the hotmail-one) is reserved almost purely for MSN.
_________________________
!

download KiXnet

Top
#75841 - 2003-07-15 02:40 PM Re: Memory() Testing
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#75842 - 2003-07-15 04:01 PM Re: Memory() Testing
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
kent, good idea.
that code would be about 5 lines and 200 strokes.
but do we really want it? [Wink]
_________________________
!

download KiXnet

Top
#75843 - 2003-07-15 04:13 PM Re: Memory() Testing
Richie19Rich77 Offline
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
#75844 - 2003-07-15 04:47 PM Re: Memory() Testing
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
if you use the upmost udf, please could you change the end:
code:
for $counter= 8 to ubound($vals) step 4
$nul=execute("$$memory=0.0 + $$memory + &"+$vals[$counter]+"/1024")
next
$memory=int(($memory +648)/1024)
endfunction

to:
for $counter= 8 to ubound($vals) step 4
$memory=0.0
$nul=execute("$$temp=&"+$vals[$counter]+"/1024")
$memory=$memory+$temp
$temp " - " $memory
?
next
$memory=($memory +648)/1024 ?
$memory ?
$memory=int($memory)
$memory ?
endfunction


and post the result?
_________________________
!

download KiXnet

Top
Page 1 of 2 12>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.074 seconds in which 0.027 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org