Error in MemoryStatus() results?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Jacobus
Enthusiast
Enthusiast
Posts: 140
Joined: Wed Nov 16, 2005 7:51 pm
Location: France
Contact:

Error in MemoryStatus() results?

Post by Jacobus »

Hello,
Can you test the MemoryStatus() functions and compare the results with your system information?
It seems there's a discrepancy between the data obtained by #PB_System_TotalSwap and #PB_System_FreeSwap
and the data obtained by #PB_System_TotalVirtual and #PB_System_TotalVirtual
Furthermore, the results obtained with PB x64 regarding virtual memory are completely insane...
The results are the same with PB 6.12 and PB 6.20, x86 and x64

My results :

Sytem :
*******
CPUName(): 13th Gen Intel(R) Core(TM) i9-13900H
CountCPUs(#PB_System_CPUs): 20
CountCPUs(#PB_System_ProcessCPUs): 20
-----------------------------------------------------
WINDOWS 11 X64 system informations
-----------------------------------------------------
Mémoire physique (RAM) installée : 32.0 Go
Mémoire physique totale : 31.7 Go
Mémoire physique disponible : 23.4 Go

Mémoire virtuelle totale : 33.7 Go
Mémoire virtuelle disponible : 24.0 Go

Espace pour le fichier d'échange : 2.00 Go

-----------------------------------------------------
PB 621 B8 / WINDOWS 11 X86
-----------------------------------------------------
MemoryStatus(#PB_System_TotalPhysical) : 31.7 Go
MemoryStatus(#PB_System_FreePhysical) : 23.6 Go

MemoryStatus(#PB_System_PageSize) : 4.00 Ko

MemoryStatus(#PB_System_TotalSwap) (Windows & Linux) : 33.7 Go
MemoryStatus(#PB_System_FreeSwap) (Windows & Linux) : 23.6 Go

MemoryStatus(#PB_System_TotalVirtual) (Windows) : 4.00 Go
MemoryStatus(#PB_System_FreeVirtual) (Windows) : 3.90 Go

-----------------------------------------------------
PB 621 B8 / WINDOWS 11 X64
-----------------------------------------------------
MemoryStatus(#PB_System_TotalPhysical) : 31.7 Go
MemoryStatus(#PB_System_FreePhysical) : 23.6 Go

MemoryStatus(#PB_System_PageSize) : 4.00 Ko

MemoryStatus(#PB_System_TotalSwap) (Windows & Linux) : 33.7 Go
MemoryStatus(#PB_System_FreeSwap) (Windows & Linux) : 24.3 Go

MemoryStatus(#PB_System_TotalVirtual) (Windows) : 131072.0 Go
MemoryStatus(#PB_System_FreeVirtual) (Windows) : 131067.9 Go

Code: Select all

Procedure.s DisplaySize(Taille.q, Unite.l = -1, NbDecimals.l = 0)
	; Taille = taille du lecteur
	; Unite = unit of size, 0 = Byte, 1 = Kb, 2 = Mb, 3 = Gb. Si = -1, The choice of unit and number of decimals will be automatic
	; NbDecimals = number of digits after the decimal point.
	
	Protected Val.q, Txt.s
	
	If Unite = -1
		NbDecimals = 0 : Unite = 0
		If Taille >= 1000 : Unite = 1 : NbDecimals = 2 : EndIf
		If Taille >= 10000 : Unite = 1 : NbDecimals = 1 : EndIf
		If Taille >= 1000000 : Unite = 2 : NbDecimals = 2 : EndIf
		If Taille >= 10000000 : Unite = 2 : NbDecimals = 1 : EndIf
		If Taille >= 1000000000 : Unite = 3 : NbDecimals = 2 : EndIf
		If Taille >= 10000000000 : Unite = 3 : NbDecimals = 1 : EndIf
		If Taille >= 10000000000000 : Unite = 4 : NbDecimals = 2 : EndIf
	EndIf
	Select Unite
		Case 0 : Val = 1 : Txt = " Bytes"
		Case 1 : Val = 1024 : Txt = " KB"
		Case 2 : Val = 1024 * 1024 : Txt = " MB"
		Case 3 : Val = 1024 * 1024 * 1024 : Txt = " GB"
		Case 4 : Val = 1024 * 1024 * 1024 * 1024 : Txt = " TB"
	EndSelect
	ProcedureReturn StrF(Taille / Val, NbDecimals) + Txt
	
EndProcedure

Debug "Sytem :"
Debug "*******"
Debug "CPUName(): " +  CPUName()
Debug "CountCPUs(#PB_System_CPUs): " + CountCPUs(#PB_System_CPUs)
Debug "CountCPUs(#PB_System_ProcessCPUs): " + CountCPUs(#PB_System_ProcessCPUs)

Debug "MemoryStatus(#PB_System_TotalPhysical): " + DisplaySize(MemoryStatus(#PB_System_TotalPhysical),-1)
Debug "MemoryStatus(#PB_System_FreePhysical): " + DisplaySize(MemoryStatus(#PB_System_FreePhysical),-1)

Debug "MemoryStatus(#PB_System_PageSize): " + DisplaySize(MemoryStatus(#PB_System_PageSize),-1)

Debug "MemoryStatus(#PB_System_TotalSwap) (Windows & Linux): " + DisplaySize(MemoryStatus(#PB_System_TotalSwap),-1)
Debug "MemoryStatus(#PB_System_FreeSwap) (Windows & Linux): " + DisplaySize(MemoryStatus(#PB_System_FreeSwap),-1)

Debug "MemoryStatus(#PB_System_TotalVirtual) (Windows): " + DisplaySize(MemoryStatus(#PB_System_TotalVirtual),-1)
Debug "MemoryStatus(#PB_System_FreeVirtual) (Windows): " + DisplaySize(MemoryStatus(#PB_System_FreeVirtual),-1)
Thank you in advance for your feedback.
Last edited by Jacobus on Mon May 05, 2025 10:44 am, edited 1 time in total.
PureBasicien tu es, PureBasicien tu resteras.
User avatar
idle
Always Here
Always Here
Posts: 5891
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Error in MemoryStatus() results?

Post by idle »

I get the same reported values as you have on win 11 but I only have 16gb of ram
MemoryStatus(#PB_System_TotalVirtual) (Windows) : 131072.0 Go
MemoryStatus(#PB_System_FreeVirtual) (Windows) : 131067.9 Go

The virtual address space is (1<<47), x64 only uses 48 bits for memory addresses
Fred
Administrator
Administrator
Posts: 18207
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Error in MemoryStatus() results?

Post by Fred »

Those results are just the value got by using GlobalMemoryStatusEx_() so it should be good (at least from Windows point of view :)).
infratec
Always Here
Always Here
Posts: 7616
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Error in MemoryStatus() results?

Post by infratec »

To verify:

Code: Select all

Define statex.MemoryStatusEx

statex\dwLength = SizeOf(MemoryStatusEx)

If GlobalMemoryStatusEx_(@statex)
  Debug Str(statex\ullTotalVirtual) + " = " + Str(MemoryStatus(#PB_System_TotalVirtual))
  Debug Str(statex\ullAvailVirtual) + " = " + Str(MemoryStatus(#PB_System_FreeVirtual))
Else
  Debug GetLastError_()
EndIf
User avatar
NicTheQuick
Addict
Addict
Posts: 1518
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Error in MemoryStatus() results?

Post by NicTheQuick »

On Linux I get this:
Sytem :
*******
CPUName(): AMD Ryzen 7 5800X 8-Core Processor
CountCPUs(#PB_System_CPUs): 16
CountCPUs(#PB_System_ProcessCPUs): 16
MemoryStatus(#PB_System_TotalPhysical): 62.7 Go
MemoryStatus(#PB_System_FreePhysical): 46.4 Go
MemoryStatus(#PB_System_PageSize): 4.00 Ko
MemoryStatus(#PB_System_TotalSwap) (Windows & Linux): 0 octets
MemoryStatus(#PB_System_FreeSwap) (Windows & Linux): 0 octets
MemoryStatus(#PB_System_TotalVirtual) (Windows): 0 octets
MemoryStatus(#PB_System_FreeVirtual) (Windows): 0 octets
This looks fine compared to `free`.

Code: Select all

nicolas@Rocky:~$ LANG=C free -mh
               total        used        free      shared  buff/cache   available
Mem:            62Gi       9,9Gi        46Gi       214Mi       7,7Gi        52Gi
Swap:             0B          0B          0B
Btw: Why are we using "octets" and not "bytes"? That's quite oldschool I must say. :D
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Fred
Administrator
Administrator
Posts: 18207
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Error in MemoryStatus() results?

Post by Fred »

'octets' is the french word for bytes :)
User avatar
Jacobus
Enthusiast
Enthusiast
Posts: 140
Joined: Wed Nov 16, 2005 7:51 pm
Location: France
Contact:

Re: Error in MemoryStatus() results?

Post by Jacobus »

NicTheQuick wrote: Mon May 05, 2025 9:51 am Btw: Why are we using "octets" and not "bytes"? That's quite oldschool I must say. :D
French is my everyday language, and sometimes I mix the two. Old school is like old pots; they make the best soup. :D

After verification, it turns out that the 128 TB limit for virtual memory, although it seems enormous, is consistent with 64-bit systems.
This is what Microsoft states. https://learn.microsoft.com/en-us/windo ... s-releases
Memory Limits for Windows and Windows Server Versions

Memory Type:
_______________________________________________________________________________
User-mode virtual address space for each 32-bit process:

Limit on X86: 2 GB and up to 3 GB with IMAGE_FILE_LARGE_ADDRESS_AWARE and 4GT.

Limit in 64-bit Windows: 2 GB with IMAGE_FILE_LARGE_ADDRESS_AWARE cleared (default)
4 GB with IMAGE_FILE_LARGE_ADDRESS_AWARE set
_______________________________________________________________________________
User-mode virtual address space for each 64-bit process:

Limit on x86: Not applicable

Limit in 64-bit Windows: With IMAGE_FILE_LARGE_ADDRESS_AWARE set (default):
x64: Windows 8.1 and Windows Server 2012 R2 or later: 128 TB
x64: Windows 8 and Windows Server 2012 or earlier: 8 TB
Intel Itanium-based systems: 7 TB
2 GB with IMAGE_FILE_LARGE_ADDRESS_AWARE cleared
_______________________________________________________________________________
Kernel-mode virtual address space:

Limit on x86: 2 GB and 1 GB to a maximum of 2 GB with 4GT

Limit in 64-bit Windows: Windows 8.1 and Windows Server 2012 R2 or later: 128 TB
Windows 8 and Windows Server 2012 or earlier: 8 TB

Code: Select all

Procedure.s DisplaySize(Taille.q, Unite.l = -1, NbDecimals.l = 0) 
  ; Taille = drive size
  ; Unite = unit of size, 0 = Byte, 1 = KB, 2 = MB, 3 = GB, 4 = TB. If = -1, the unit and number of decimal places will be chosen automatically.
  ; NbDecimals = number of digits after the decimal point.	
	Protected Val.q, Txt.s	
	If Unite = -1
		NbDecimals = 0 : Unite = 0
		If Taille >= 1000 : Unite = 1 : NbDecimals = 2 : EndIf
		If Taille >= 10000 : Unite = 1 : NbDecimals = 1 : EndIf
		If Taille >= 1000000 : Unite = 2 : NbDecimals = 2 : EndIf
		If Taille >= 10000000 : Unite = 2 : NbDecimals = 1 : EndIf
		If Taille >= 1000000000 : Unite = 3 : NbDecimals = 2 : EndIf
		If Taille >= 10000000000 : Unite = 3 : NbDecimals = 1 : EndIf
		If Taille >= 1000000000000 : Unite = 4 : NbDecimals = 2 : EndIf
		If Taille >= 10000000000000 : Unite = 4 : NbDecimals = 1 : EndIf
	EndIf
	Select Unite
		Case 0 : Val = 1 : Txt = " Bytes"
		Case 1 : Val = 1024 : Txt = " KB"
		Case 2 : Val = 1024 * 1024 : Txt = " MB"
		Case 3 : Val = 1024 * 1024 * 1024 : Txt = " GB"
		Case 4 : Val = 1024 * 1024 * 1024 * 1024 : Txt = " TB"
	EndSelect
	ProcedureReturn StrF(Taille / Val, NbDecimals) + Txt
EndProcedure
Define statex.MemoryStatusEx
statex\dwLength = SizeOf(statex)
If GlobalMemoryStatusEx_(@statex)
  Debug "Total Virtual Memory = "+DisplaySize(statex\ullTotalVirtual,-1) 
   Debug "Available Virtual Memory = "+DisplaySize(statex\ullAvailVirtual,-1)  
   Debug "Extended memory available = "+DisplaySize(statex\ullAvailExtendedVirtual,-1)  ; must be 0  
   Debug "Total physical memory = "+DisplaySize(statex\ullTotalPhys,-1)
   Debug "Available physical memory = "+DisplaySize(statex\ullAvailPhys,-1)
   Debug "Physical memory in use = "+Str(statex\dwMemoryLoad)+" %"    
   Debug "Total expanded memory = "+DisplaySize(statex\ullTotalPageFile,-1)
   Debug "Available expanded memory = "+DisplaySize(statex\ullAvailPageFile,-1)
 Else
   Debug GetLastError_()
 EndIf
PureBasicien tu es, PureBasicien tu resteras.
Post Reply