Archive: Detect Free RAM?


Detect Free RAM?
  How can we detect free RAM in the end-user machine? :weird:


System does it again :D

System::Alloc 32

Pop$1
System::Call "Kernel32::GlobalMemoryStatus(i) v (r1)"
>System::Call "*$1(&i4 .r2, &i4 .r3, &i4 .r4, \
&i4 .r5, &i4 .r6, &i4.r7, &i4 .r8, &i4 .r9)"
>System::Free $1
DetailPrint "Structure size (useless): $2 Bytes"
>DetailPrint "Memory load: $3%"
>DetailPrint "Total physical memory: $4 Bytes"
>DetailPrint "Free physical memory: $5 Bytes"
>DetailPrint "Total page file: $6 Bytes"
>DetailPrint "Free page file: $7 Bytes"
>DetailPrint "Total virtual: $8 Bytes"
>DetailPrint "Free virtual: $9 Bytes"

wao
  thanks !!!!

:eek: didnĀ“t know that trick :eek:


in mirc, just type /stat :)

oh wait, you need moo.dll :P


Ok, try everything..... but how can we convert to MB in Nsis,
because the $4 return in Bytes ?


This one for example:
http://nsis.sourceforge.net/archive/....php?pageid=78


jejeje...yeah...IntOp... does it !!!!

Thanks :D


I love system.dll.


Old thread but I was trying to figure out how to determine how to detect the amount of system memory at install time and came across this via google.

This was very useful and got me on the right track. Most of our install targets are 64 bit systems so I needed a solution that could handle this (not 32 bit integer limited) and found I needed to use GlobalMemoryStatusEX instead of GlobalMemoryStatus . One key difference is that the structure passed to GlobalMemoryStatusEx, MEMORYSTATUSEX, must have the structure size set (This isn't necessary with GlobalMemoryStatus and MEMORYSTATUS. If anyone's interested here's the code I used:


## allocate
System::Alloc 64
Pop $0
## set
# GlobalMemoryStatusEx requires structure size to set in
# MEMORYSTATUSEX instance passed in as argument
System::Call "*$0(i 64, i 0, l 0, l 0, l 0, l 0, l 0, l 0, l 0)"
## call
System::Call "Kernel32::GlobalMemoryStatusEx(i r0)"
## get
System::Call "*$0(i.r1, i.r2, l.r3, l.r4, l.r5, l.r6, l.r7, l.r8, l.r9)"
## free
System::Free $0
## print
DetailPrint "Structure size: $1 bytes"
DetailPrint "Memory load: $2%"
DetailPrint "Total physical memory: $3 bytes"
DetailPrint "Free physical memory: $4 bytes"
DetailPrint "Total page file: $5 bytes"
DetailPrint "Free page file: $6 bytes"
DetailPrint "Total virtual: $7 bytes"
DetailPrint "Free virtual: $8 bytes"
DetailPrint "Free extended virtual: $9 bytes"


I thought this might save someone some time.

I apologize it it's poor etiquette to dredge up old threads. Every forum seems to have different rules...

edit:
The URLs posted above were function and structure names with links to Microsoft's MSDN docs. Right now all I see is "URL submitted by user" Sorry if this makes the post unreadable..

You should add this code to the Wiki page:
http://nsis.sourceforge.net/Determin..._System_plugin

And here are the links again so everyone can read them.

First link to GlobalMemoryStatusEx:
http://msdn2.microsoft.com/en-us/library/aa366589(VS.85).aspx

Second link to GlobalMemoryStatus:
http://msdn2.microsoft.com/en-us/library/aa366586(VS.85).aspx

Third link to MEMORYSTATUSEX:
http://msdn2.microsoft.com/en-us/library/aa366770(VS.85).aspx

Fourth link to MEMORYSTATUS:
http://msdn2.microsoft.com/en-us/library/aa366772(VS.85).aspx


Just a heads up...

If you are going to manipulate values returned from the output of GlobalMemoryStatusEX use Math::Script instead of IntOp. IntOp functionality appears to be limited to signed 4 byte integers...


the system plugin has Int64Op


the system plugin has Int64Op
Excellent! Math::Script seemed a little too heavy weight for my needs...

Also, you may want to change your sig to Int64Op $PostCount $PostCount + 1 as your post count reaches 2^(32-1)

How do I make it work on 64bit ? (returns negative numbers)
  on 64bit The following code

  System::Alloc 32

Pop$1
System::Call "Kernel32::GlobalMemoryStatus(i) v (r1)"
System::Call "*$1(&i4 .r2, &i4 .r3, &i4 .r4, &i4 .r5, \
&i4 .r6, &i4.r7, &i4 .r8, &i4 .r9)"
System::Free $1

; $5 => Free RAM
; $4 => Total RAM
IntOp $R5$5 / 1048576 ; 1048576 = 1024*1024, or MegaX
IntOp $R4$4 / 1048576 ; 1048576 = 1024*1024, or MegaX
MessageBox MB_OK "R5: $R5 5: $5 R4: $R4 4: $4"
gives this (also picture attached):
R5: -813 5: -852815872 R4: -256 4: -269082624

the real total memory is: 3.75GB of RAM

How do I make this work for a 64 bit system?
if pissible hoe to make one coade to work for both 64bit and 32bit?

Thanks!

Have you read the entire thread? I would guess "no"...


Get negative crap
  Hi,
Sorry for not reading the thread :-).
So after this code:

System::Alloc 64

Pop$0
## set
# GlobalMemoryStatusEx requires structure size to set in
# MEMORYSTATUSEX instance passed in as argument
System::Call "*$0(i 64, i 0, l 0, l 0, l 0, l 0, l 0, l 0, l 0)"
## call
System::Call "Kernel32::GlobalMemoryStatusEx(i r0)"
## get
System::Call "*$0(i.r1, i.r2, l.r3, l.r4, l.r5, l.r6, l.r7, l.r8, l.r9)"
## free
System::Free $0

MessageBox MB_OK "TotalRAM: $3 FreeRAM: $4"
IntOp $vTotalRAMtemp $3 * 1
IntOp $vTotalRAM $vTotalRAMtemp/ 1


MessageBox MB_OK "TotalRAM: $vTotalRAM"
; $4 => Free RAM
; $3 => Total RAM

IntOp $vTotalRAM$3 / 1048576 ; 1048576 = 1024*1024, or MegaX
IntOp $vFreeRAM$4 / 1048576 ; 1048576 = 1024*1024, or MegaX
MessageBox MB_OK "vTotalRAM: $vTotalRAM"
on a 64 bit machine I get: -262776
if I printout the $3 it gives the right value in bytes: 4025884672.
in fact I get negative number even if I do $3 +1

thanks

In posts subsequent to the GlobalMemoryStatusEX post you'll find that you need to use System::Int64Op to do 64 bit math.

My code looks like:


System::Alloc 64
Pop $0
System::Call "*$0(i 64)"
System::Call "Kernel32::GlobalMemoryStatusEx(i r0)"
System::Call "*$0(i, i, l.r1, l, l, l, l, l, l)"
System::Free $0
; convert bytes to megabytes
System::Int64Op $1 / 1048576
Pop $1

THANKS ALOT!!!!!!!!!!!!
  THANKS ALOT!!!!!!!!!!!!