Free RAM in Windows

Share your advanced PureBasic knowledge/code with the community.
Randy Walker
Addict
Addict
Posts: 1208
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

Free RAM in Windows

Post by Randy Walker »

A little something I picked up from Meta AI in WhatsApp And thought I should share:

Code: Select all

Procedure.s RAM()
Define mem.MEMORYSTATUSEX
mem\dwLength = SizeOf(MEMORYSTATUSEX)
If OpenLibrary(0, "kernel32.dll")
  CallFunction(0, "GlobalMemoryStatusEx", @mem)
  Ret$ = Str(mem\ullAvailPhys / (1024 * 1024)) + " MB free"
  CloseLibrary(0)
  ProcedureReturn ret$
EndIf
EndProcedure
Debug RAM()
You might want to do Debug (Val(RAM())/1024)*1000 instead.

ALSO SEE: viewtopic.php?p=282628#p282628
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
Bisonte
Addict
Addict
Posts: 1333
Joined: Tue Oct 09, 2007 2:15 am

Re: Free RAM in Windows

Post by Bisonte »

You mean

Code: Select all

Debug Str(MemoryStatus(#PB_System_FreePhysical) / (1024 * 1024)) + " MB free"
without Windows API ? ;)
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.)
Randy Walker
Addict
Addict
Posts: 1208
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

Re: Free RAM in Windows

Post by Randy Walker »

Bisonte wrote: Fri Jan 30, 2026 7:50 am You mean

Code: Select all

Debug Str(MemoryStatus(#PB_System_FreePhysical) / (1024 * 1024)) + " MB free"
without Windows API ? ;)
Hey!!!! There's another cool tip, Except for one thing. Does not agree with my Task Manager. Any ideas why?
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Fred
Administrator
Administrator
Posts: 18499
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Free RAM in Windows

Post by Fred »

MemoryStatus() use also GlobalMemoryStatusEx(), so the results should be identical.
Randy Walker
Addict
Addict
Posts: 1208
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

Re: Free RAM in Windows

Post by Randy Walker »

Fred wrote: Fri Jan 30, 2026 9:19 am MemoryStatus() use also GlobalMemoryStatusEx(), so the results should be identical.
Seems to be ok if I do this:

Code: Select all

Debug Str((MemoryStatus(#PB_System_FreePhysical) / 1024/1024)) + " MB free"
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Post Reply