Page 1 of 1 1
Topic Options
#201809 - 2011-03-29 03:48 PM Problems with Memory() UDF and Windows 7 x64
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Hey Glenn. I'm having issues with the Memory() UDF on Win7 x64. It reports 3346 on a system that has 8gb of ram.

Here is my .translated value.

 Code:
010000000000000000000000000000000300000003010000001000000000000000e00900000000000301000000001000000000000000e8cf000000000701000200000000010000000000300100000000


Any ideas?

Top
#201812 - 2011-03-29 06:04 PM Re: Problems with Memory() UDF and Windows 7 x64 [Re: Allen]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Tested on my Win7 64bit laptop as well just to have a 2nd test. It returned '2811' and it has 3.00GB with 2.74 usable listed.
Top
#201814 - 2011-03-30 12:29 AM Re: Problems with Memory() UDF and Windows 7 x64 [Re: ShaneEP]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Ugh - going to have to go down memory lane to look at that one! ;\) I'll see what I can come up with.

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

Top
#201816 - 2011-03-30 02:53 AM Re: Problems with Memory() UDF and Windows 7 x64 [Re: Glenn Barnas]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
 Quote:
Ugh

Looking at that code would certainly deserve your response. \:\)

I had a old script that had the got the memory slot info, and I added the memory info to it tonight... so for me there is no hurry now. Thanks though.

GetMemoryInfo() - Get Information Related to the Memory and Slots on a PC


Top
#207962 - 2013-10-30 02:28 PM Re: Problems with Memory() UDF and Windows 7 x64 [Re: Allen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Since this was just recently brought up, I tested this again, on a completely different PC, and this time with Windows 8 Pro x64 and 8GB ram. Memory reports 3579. Not sure what is going on but here is my .translated value:

 Quote:

010000000000000000000000000000000700000003010000001000000000000000e0090000000000
030100000000100000000000002000000000000003010000003010000000000000c009de00000000
0301000000b0dede0000000000100000000000000301000000f0e2de0000000000807a0000000000
0301000000207fdf0000000000e000000000000007010002000000000100000000001f0100000000


Again, for me this is super low prioity. Just thought I would let you know Glenn.


Edited by Allen (2013-10-30 02:29 PM)

Top
#207964 - 2013-10-30 05:49 PM Re: Problems with Memory() UDF and Windows 7 x64 [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
This is odd.. all the systems I've checked, the .translated value contains either 160 or 200 characters. You have 320 characters in yours. Checking my docs on how that key works, this doesn't make sense. I'll increase the RAM in my W-7 VM to 8GB and see what happens, although I've tested this on physical systems with 16 and 32G running Server 2008r2.

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

Top
#207965 - 2013-10-30 11:48 PM Re: Problems with Memory() UDF and Windows 7 x64 [Re: Glenn Barnas]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
The script I was using was ancient, and I might have displayed two values (160x2). I'll check the .translated value again when I get a minute.
Top
#207967 - 2013-10-31 12:47 AM Re: Problems with Memory() UDF and Windows 7 x64 [Re: Allen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
I just redid the test with same results. It returns 3579 for 8GB and the value that holds .translated, ie $_MemMap = 010000000000000000000000000000000700000003010000001000000000000000e0090000000000
030100000000100000000000002000000000000003010000003010000000000000c009de00000000
0301000000b0dede0000000000100000000000000301000000f0e2de0000000000807a0000000000
0301000000207fdf0000000000e000000000000007010002000000000100000000001f0100000000


If you are not seeing this, and no one else is complaining, don't worry about it.

Top
#207968 - 2013-10-31 01:07 AM Re: Problems with Memory() UDF and Windows 7 x64 [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Just strange - I've run it on the gamut of systems - XP, Win-7 and Win-8, Server 2003, 2008, 2008r2 and even 2012 and have never seen that many lines in the registry. Do you have an AMD CPU or one of those that has 3-way interleaving?

I tried playing with different offsets, and subsets of the data. Only when ignoring the first 64 chars do I get something close to 8G (7134 or some such..) I even tried the alternate method of using the last 8 chars, but they are always all zeros.

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

Top
#207969 - 2013-10-31 02:53 AM Re: Problems with Memory() UDF and Windows 7 x64 [Re: Glenn Barnas]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
My old PC was an AMD, but the one I am using now is Intel i7.
Top
#207981 - 2013-11-01 01:50 PM Re: Problems with Memory() UDF and Windows 7 x64 [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
OK - all systems in house are P4 or XEON class Intel. My AMD system died and was replaced with a P4. I'm picking up an i7 w/ 8G tonight, so should be able to see what's going on directly.

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

Top
#207990 - 2013-11-03 02:40 PM Re: Problems with Memory() UDF and Windows 7 x64 [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
OK - I think I've got it!

I've tested the new code on Windows 7 (x86/64), Windows 8 (x86/64), Server 2003 (x86), Server 2008 (x64), and Server 2012 (x64) with accurate results. Memory sizes ranged from 2GB to 12GB. I also tested by injecting your .Translated value and got 8153MB - about 40MB off from the physical 8192MB. This is usually a memory or BIOS window.

Here's the code to test with:
 Code:
Break On

$Mem = Memory()				; get RAM size from local computer

$MSize = 512				; Smallest RAM module in service

$Ma = $Mem / $MSize			; Divide by smallest module size
If $Mem Mod $MSize $Ma = $Ma + 1 EndIf	; If a fractional module is detected, add another full module
$Ma = $Ma * $MSize			; calc installed RAM by multiplying modules * ModuleSize

'  Reported: ' $Mem ?
'  Adjusted: ' $Ma ?
'Difference: ' $Ma - $Mem ?
' Gigabytes: ' $Ma / 1024 ?
and here's the updated UDF
 Code:
;;FUNCTION		Memory() 
;; 
;;AUTHOR		Glenn Barnas
;; 
;;ACTION		Returns the amount of Available Physical RAM in a local or remote system 
;; 
;;SYNTAX		Memory([system]) 
;; 
;;VERSION		4.0 
;; 
;;DATE			v1.0 - 2004/02/04
;; 
;;DATE REVISED		v2.0 - 2005/02/25 - updated to allow larger memory sizes (x86)
;;			v3.0 - 2007/10/05 - rewrite to support x64 systems, tighten code
;;			v4.0 - 2013/11/02 - rewrite to detect large memory blocks on post-Vista platforms
;; 
;;PARAMETERS		System - OPTIONAL - name of system to query. Default is local system
;;
;;REMARKS		Returns Physical RAM size available to the O/S using registry memory allocation map
;;			Returns @ERROR on registry read failure, or 13 / "Data is Invalid" if reg is empty
;;			DOES NOT return physical hardware ram value! Some systems allocate RAM to BIOS cache 
;;			or video adapters and this memory is not reported. This can be adjusted for using
;;			the second example below.
;; 
;;RETURNS		Integer - Available Physical RAM (in Megabytes) 
;; 
;;DEPENDENCIES		None 
;; 
;;TESTED WITH		WinXP, Vista, Win7, Win8
;;			Windows Server 2000, 2003, 2008, 2012
;;			Tested with up to 16G of RAM 
;; 
;;EXAMPLES		$RAM = Memory('ThatPC')		; Get the available RAM from a remote computer
;;			
;;			; Adjust for BIOS/Video ram to estimate total physical RAM by using the smallest
;;			; deployed DIMM module as an increment. Use "1024" for full GB increments.
;;			; If the GB flag is used, this method must be adjusted to define MSize in GB values
;;			; (e.g. 0.5 instead of 512). 
;;			$MSize = 512			; Size of smallest RAM module (DIMM)
;;			
;;			$Mem = Memory()			; get reported memory
;;			$Ma  = $Mem / $MSize		; determine number of modules installed
;;			
;;			; If a fractional module is detected, add another full module
;;			; this accounts for a fractional module used for BIOS cache or video RAM
;;			If $Mem Mod $MSize $Ma = $Ma + 1 EndIf
;;			
;;			; $Mem now holds a value based more closely on installer rather than available RAM
;;			$Mem = $Ma * $MSize		; Memory is #_modules * Mod_Size
;;			
;; 
;
Function Memory(Optional $_System, Optional $_fGB)

  Dim $_MemMap				; Physical Memory Map
  Dim $_Start, $_End, $_Step		; for/next start & step increment
  Dim $_Sum				; running sum of memory from map
  Dim $_Idx				; temporary index var
  Dim $_iMem				; Memory region size index
  Dim $_Error				; Error placeholder

  ; Insure $_System has "\\System\" format if it is specified 
  If $_System <> ''
    $_System = '\\' + Join(Split($_System, '\'), '', 3) + '\'
  EndIf

  ; Get the memory value from the registry 
  $_Idx = $_System + 'HKLM\hardware\resourcemap\system resources\physical memory'
  $_MemMap = ReadValue($_Idx, '.Translated')

  ; Check for invalid read and Return 
  If Len($_MemMap) = 0 Or @ERROR
    $Memory = 0				; return 0 Mbytes 
    $_Error = IIf(@ERROR, @ERROR, 13) 	; Return "Data is Invalid" if no error but data is blank 
    Exit $_Error
  EndIf

  ; determine system's O/S type based on architecture
  $_Idx = $_System + 'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
  If ReadValue($_Idx, 'PROCESSOR_ARCHITECTURE') = 'AMD64'
    $_Step  = 40	; Define the step size based on the O/S Architecture
    $_Start = 33	; Offset where memory descriptor blocks start
    $_Sum   = 0.0	; no unreported base memory to account for
    $_iMem  = 10	; Memory size index
  Else
    $_Step  = 32	; Define the step size based on the O/S Architecture
    $_Start = 41	; Offset where memory descriptor blocks start
    $_Sum   = 737280.0	; account for base memory not identified in memory map - x86 only
    $_iMem  = 2		; Memory size index
  EndIf
  $_End = Len($_MemMap) - 8

  For $_Idx = $_Start to $_End Step $_Step
    $_Block = SubStr($_MemMap, $_Idx, $_Step)

    If SubStr($_Block, $_iMem, 1) > 3
      $_Sum = $_Sum + CDbl(Val('&' + SubStr($_Block, $_Step - 1, 2))) * 4294967296.0
                    + CDbl(Val('&' + SubStr($_Block, $_Step - 3, 2))) * 16777216.0
                    + CDbl(Val('&' + SubStr($_Block, $_Step - 5, 2))) * 65536.0
                    + CDbl(Val('&' + SubStr($_Block, $_Step - 7, 2))) * 256.0
                    + CDbl(Val('&' + SubStr($_Block, $_Step - 9, 2)))
    Else
      $_Sum = $_Sum + CDbl(Val('&' + SubStr($_Block, $_Step - 1, 2))) * 16777216.0
                    + CDbl(Val('&' + SubStr($_Block, $_Step - 3, 2))) * 65536.0
                    + CDbl(Val('&' + SubStr($_Block, $_Step - 5, 2))) * 256.0
                    + CDbl(Val('&' + SubStr($_Block, $_Step - 7, 2)))
    EndIf
  Next

  ; Sum is in Bytes - return the total as megabytes
  $Memory = CInt($_Sum / 1048576)
  Exit 0

EndFunction
Let me know if this works for you. I still need to test some older platforms, particularly Server 2003 or XP 64-bit systems. Not sure if I should worry about older platforms than that.. \:\)

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

Top
#207992 - 2013-11-03 02:51 PM Re: Problems with Memory() UDF and Windows 7 x64 [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Just some additional insight..

The original code assumed that each reported memory region was 8-10 bytes. None of the systems I tested actually used a 10-byte region (until now!). The problem is that the 10-byte region is mapped differently than the standard 8-byte region. I had to first detect the 10-byte region and then shift the calculation slightly when it was found. Might need to update this again when we hit TB of RAM installed. \:\)

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

Top
#207993 - 2013-11-03 04:16 PM Re: Problems with Memory() UDF and Windows 7 x64 [Re: Glenn Barnas]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Wow... nice work Glenn.

I have access to a 16GB system I'll check it on when I get a minute.

Good Job.

Top
#208000 - 2013-11-05 05:02 PM Re: Problems with Memory() UDF and Windows 7 x64 [Re: Glenn Barnas]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Results on a Win2K8 R2 server with 20GB of memory running on vSphere 5.1.

 Quote:

Reported: 20480
Adjusted: 20480
Difference: 0
Gigabytes: 20


Thanks for updating Glenn.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#208002 - 2013-11-05 05:47 PM Re: Problems with Memory() UDF and Windows 7 x64 [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Great - thanks for the feedback, Mart!

I'll be spinning up some XP X86 and X64 VMs, plus a Server 2003 X64 to complete the validation in the next few days. I've got just one Server 2003 x86 platform left for validation now, and all the workstations have been upgraded to W7, W8, or W8.1.

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

Top
#208003 - 2013-11-05 06:01 PM Re: Problems with Memory() UDF and Windows 7 x64 [Re: Glenn Barnas]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Server 2012 R2 with 16GB reports 16339.

My Win 8 x64 with 8GB now reports 8153.

Mucho better \:\)

Top
#208004 - 2013-11-05 08:42 PM Re: Problems with Memory() UDF and Windows 7 x64 [Re: Glenn Barnas]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
I have one Win2K server still running and it also seems to work on this “slightly older” OS.

 Quote:

Reported: 3840
Adjusted: 4096
Difference: 256
Gigabytes: 4
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#208024 - 2013-11-08 09:35 AM Re: Problems with Memory() UDF and Windows 7 x64 [Re: Mart]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
I'll try it out on one of my Windows Servers with 64GB of RAM tomorrow if I get time.
Top
Page 1 of 1 1


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

Who's Online
0 registered and 351 anonymous users online.
Newest Members
rrosell, PatrickPinto, Raoul, Timothy, Jojo67
17877 Registered Users

Generated in 0.106 seconds in which 0.064 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