- NSIS Discussion
- NSIS Get System Memory
Archive: NSIS Get System Memory
vinnietran
3rd April 2006 17:43 UTC
NSIS Get System Memory
I am using this to get the system memory:
# allocate
System::Alloc 32
Pop $1
# call
System::Call "Kernel32::GlobalMemoryStatus(i r1)"
# get
System::Call "*$1(i.r2, i.r3, i.r4, i.r5, i.r6, i.r7, i.r8, i.r9)"
# free
System::Free $1
# print
DetailPrint "Structure size: $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"
But for some reason, it is not showing the correct memory information. Example, I have a system with 4GB memory. I ran the code above to get the memory information and I am only getting about 2GB. Can anyone help me please?
Thanks.
Afrow UK
3rd April 2006 18:18 UTC
Probably a stupid question, but does Windows say that you have 4GB under My Computer?
-Stu
vinnietran
3rd April 2006 18:50 UTC
Afrow. That is not a stupid question.
Yes. The system say 4GB. I am running this on Windows 2003.
Takhir
3rd April 2006 18:55 UTC
System plug-in vars looks like signed int (or I not found DWORD | unsigned mentioned in it's Readme), so I always have in mind that problems may occure with handles and other unsigned. So may be good to update data types set (or docs if there are some tricks for DWORD)
vinnietran
3rd April 2006 21:23 UTC
When I ran the sample codes above from any Windows 2000, 2003, and XP with memory between 3GB-4GB of memory, I am getting the same number:
Here is the output for physical memory: 2147483647 bytes (this is about 2GB right - :) if my calculation is correct).
Is there a limitation with calling this Kernel32::GlobalMemoryStatus?
The system shows 4GB, but I am getting only 2GB, any other way to get the correct system physical memory information?
Thanks in advance.
Afrow UK
3rd April 2006 21:33 UTC
Use GlobalMemoryStatusEx instead of GlobalMemoryStatus.
http://www.cygwin.com/ml/cygwin/2004-12/msg00156.html
-Stu
vinnietran
3rd April 2006 21:42 UTC
Stu
Any sample, what parameters do I need to pass in.
I tried it but it returns with 0s.
Thanks.
vinnietran
4th April 2006 00:45 UTC
Hello Everyone. Does anyone have the example for GlobalMemoryStatusEx which Stu mentioned above. I tried it but it gave me whole bunch of zeros. I think I have problem with the output
System::Call "Kernel32::GlobalMemoryStatus(i r1)"
# get
System::Call "*$1(i.r2, i.r3, i.r4, i.r5, i.r6, i.r7, i.r8, i.r9)"
Thanks in advance.
vinnietran
4th April 2006 00:46 UTC
ooops sorry correction
System::Call "Kernel32::GlobalMemoryStatusEx(i r1)"
# get
System::Call "*$1(i.r2, i.r3, i.r4, i.r5, i.r6, i.r7, i.r8, i.r9)"
Afrow UK
4th April 2006 08:48 UTC
GlobalMemoryStatusEx uses the MEMORYSTATUSEX structure which has another parameter that specifies the extended memory (ullAvailExtendedVirtual).
Try:
System::Call "*$1(i.r2, i.r3, i.r4, i.r5, i.r6, i.r7, i.r8, i.r9, i.r10)"
# $R0 = ullAvailExtendedVirtual
-Stu
vinnietran
4th April 2006 15:06 UTC
Stu,
That's what I thought too. This is the code I executed.
# allocate
System::Alloc 32
Pop $1
# call
System::Call "Kernel32::GlobalMemoryStatusEx(i r1)"
# get
System::Call "*$1(i.r2, i.r3, i.r4, i.r5, i.r6, i.r7, i.r8, i.r9, i.r10)"
# free
System::Free $1
# print
DetailPrint "Structure size: $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"
And this is what I get for returned:
Structure size: 0 bytes
Memory load: 0%
Total physical memory: 0 bytes
Free physical memory: 0 bytes
Total page file: 0 bytes
Free page file: 0 bytes
Total virtual: 0 bytes
Free virtual: 0 bytes
Completed
Is it might have to do what datatypes it is? I'd tried with different datatypes such as l-large int, t-string, etc.
--Vinnie
kichik
4th April 2006 15:36 UTC
Most of the values in MEMORYSTATUSEX are 64-bit unsigned integers. You should use 'l' instead of 'i' in the System plug-in call. You should also allocate more space as the structure is bigger and initialize the first member of the structure with its size.
# allocate
System::Alloc 64
Pop $1
# init
System::Call "*$1(i64)"
# call
System::Call "Kernel32::GlobalMemoryStatusEx(i r1)"
# get
System::Call "*$1(i.r2, i.r3, l.r4, l.r5, l.r6, l.r7, l.r8, l.r9, l.r10)"
# free
System::Free $1
# print
DetailPrint "Structure size: $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"
vinnietran
4th April 2006 15:44 UTC
Thank You Very Much Kichik. You are the GOD. This worksssssss (well, at least on my box :) ). Let me go try it on the other system.
vinnietran
4th April 2006 19:01 UTC
How can I convert the Total Physical Memory which is in bytes to Mbytes?
I tried "IntOp $4 $4 / 1048576 but it is returning 0.
I guess IntOp can only handle so much. Is there another way to convert?
Thanks.
kichik
4th April 2006 19:02 UTC
System::Int64Op $4 / 1048576
Pop $4
vinnietran
4th April 2006 19:11 UTC
Thanks.