Physically installed RAM

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Physically installed RAM

Post by coco2 »

Currently MemoryStatus() reports the amount of RAM available to the OS as far as I understand it. Would it be possible to report the physically installed RAM? Such code in C++ is as follows:

Code: Select all

#include <windows.h>
#include <iostream>

unsigned long long MemoryInstalled()
{
	unsigned long long physicalMemory = 0;
	GetPhysicallyInstalledSystemMemory(&physicalMemory);
	return physicalMemory;
}

using namespace std;

int main()
{
	cout << "Installed RAM: " << MemoryInstalled() / (1024 * 1024) << "GB" << endl;
	return EXIT_SUCCESS;
}
User avatar
mk-soft
Always Here
Always Here
Posts: 6209
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Physically installed RAM

Post by mk-soft »

Code: Select all

size = MemoryStatus(#PB_System_TotalPhysical)
Debug "TOTAL: " + Str(size / (1024*1024)) + " MB"
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Physically installed RAM

Post by coco2 »

It returns a value different to the physically installed RAM.

Code: Select all

size = MemoryStatus(#PB_System_TotalPhysical)
Debug "TOTAL: " + FormatNumber(size / (1024*1024*1024), 4) + " GB"
TOTAL: 31.9495 GB

The C++ code I posted will return 32GB
User avatar
mk-soft
Always Here
Always Here
Posts: 6209
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Physically installed RAM

Post by mk-soft »

Perhaps without GPU buffer or a bug

Code: Select all

Import ""
  GetPhysicallyInstalledSystemMemory(Size)
EndImport

size = MemoryStatus(#PB_System_TotalPhysical)
GetPhysicallyInstalledSystemMemory(@size2)

Debug "TOTAL PB: " + Str(size / 1024) + " kB"
Debug "TOTAL API: " + Str(size2) + " kB"
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Physically installed RAM

Post by coco2 »

Maybe not a bug, I think GlobalMemoryStatusEx() might be the same as PB. I read somewhere that it is the amount available to the OS.

Do you know how to import GlobalMemoryStatusEx()?
User avatar
mk-soft
Always Here
Always Here
Posts: 6209
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Physically installed RAM

Post by mk-soft »

You are right. Its not a bug

Code: Select all

Global info.MEMORYSTATUSEX
info\dwLength = SizeOf(MEMORYSTATUSEX)
r1 = GlobalMemoryStatusEx_(@info)
If r1
  Debug "TOTAL API: " + info\ullTotalPhys
Else
  Debug "Failed"
EndIf
Debug "TOTAL PB: " + MemoryStatus(#PB_System_TotalPhysical)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Re: Physically installed RAM

Post by Bisonte »

In C, no decimal place is calculated, but in your PB formula it is..... If you do the same in PB as in C, the result is the same:

Code: Select all

size = MemoryStatus(#PB_System_TotalPhysical)
Debug "TOTAL: " + FormatNumber(size / (1024*1024*1024), 0) + " GB"
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Physically installed RAM

Post by coco2 »

The results aren't the same:

GetPhysicallyInstalledSystemMemory(): 33554432 KB
PureBasic: 33501516 KB
Post Reply