Got an idea for enhancing PureBasic? New command(s) you'd like to see?
coco2
Enthusiast
Posts: 461 Joined: Mon Nov 25, 2013 5:38 am
Location: Australia
Post
by coco2 » Sun Aug 06, 2023 10:54 am
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;
}
mk-soft
Always Here
Posts: 6209 Joined: Fri May 12, 2006 6:51 pm
Location: Germany
Post
by mk-soft » Sun Aug 06, 2023 11:00 am
Code: Select all
size = MemoryStatus(#PB_System_TotalPhysical)
Debug "TOTAL: " + Str(size / (1024*1024)) + " MB"
coco2
Enthusiast
Posts: 461 Joined: Mon Nov 25, 2013 5:38 am
Location: Australia
Post
by coco2 » Sun Aug 06, 2023 11:08 am
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
mk-soft
Always Here
Posts: 6209 Joined: Fri May 12, 2006 6:51 pm
Location: Germany
Post
by mk-soft » Sun Aug 06, 2023 11:42 am
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"
coco2
Enthusiast
Posts: 461 Joined: Mon Nov 25, 2013 5:38 am
Location: Australia
Post
by coco2 » Sun Aug 06, 2023 12:14 pm
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()?
mk-soft
Always Here
Posts: 6209 Joined: Fri May 12, 2006 6:51 pm
Location: Germany
Post
by mk-soft » Sun Aug 06, 2023 12:23 pm
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)
Bisonte
Addict
Posts: 1305 Joined: Tue Oct 09, 2007 2:15 am
Post
by Bisonte » Mon Aug 07, 2023 3:30 am
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"
P ureB asic 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
Posts: 461 Joined: Mon Nov 25, 2013 5:38 am
Location: Australia
Post
by coco2 » Mon Aug 07, 2023 5:23 am
The results aren't the same:
GetPhysicallyInstalledSystemMemory(): 33554432 KB
PureBasic: 33501516 KB