Thanks. I dont know why but ive always had an urge to add this info from my programs : up until now i couldnt
Code archives/Miscellaneous/System Memory
This code has been declared by its author to be Public Domain code.
Download source code
| Code to list available and total system memory. |
; Required Userlib ;.lib "kernel32.dll" ;GlobalMemoryStatus%(lpBuffer*) Graphics 640, 300, 16, 2 SetBuffer BackBuffer() Type MEMORYSTATUS Field dwLength% Field dwMemoryLoad% Field dwTotalPhys% Field dwAvailPhys% Field dwTotalPageFile% Field dwAvailPageFile% Field dwTotalVirtual% Field dwAvailVirtual% End Type m.MEMORYSTATUS = New MEMORYSTATUS MemTime = CreateTimer(60) Repeat Cls GlobalMemoryStatus m.MEMORYSTATUS Text 1, 1, (m\dwAvailPhys% / 1024) + "kbs" + " / " + (m\dwTotalPhys% / 1024) + "kbs" Delay 5 WaitTimer MemTime: Flip 0 Until KeyDown(1) |
Comments
You're welcome. Thank you for the feeback :)
dont we need a decl file?
; Required Userlib
;.lib "kernel32.dll"
;GlobalMemoryStatus%(lpBuffer*)
;.lib "kernel32.dll"
;GlobalMemoryStatus%(lpBuffer*)
I put the DLL file in the userlibs folder but still get an error
...
kernel32.dll is already in system32
kernel32.dll is already in system32
Slenkar, you don't need to do anything with the actual kernel32.dll. You need to have/create a text file called user32.decls in your userlibs folder, put this in it, save it, then restart Blitz:
.lib "kernel32.dll"
GlobalMemoryStatus%(lpBuffer*)
Here is another, perhaps easier to understand version of Eikon's program:
.lib "kernel32.dll"
GlobalMemoryStatus%(lpBuffer*)
Here is another, perhaps easier to understand version of Eikon's program:
;=============================== ;TotalSysMem() and AvailSysMem() ;=============================== ;Two functions that use userlibs to access total and available system memory. ;To work, you need to add the following to your decls file in your userlib folder. ;.lib "kernel32.dll" ;GlobalMemoryStatus%(lpBuffer*) ;Reference ;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/globalmemorystatus.asp ;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/memorystatus_str.asp Print "TotalSysMem() = " + TotalSysMem() + " bytes" Print "AvailSysMem() = " + AvailSysMem() + " bytes" WaitKey() End ;This function returns the available physical memory on the user's PC. ;This excludes virtual memory, which can be created on disk, and ;available video memory, which can be accessed using the Blitz AvailVidMem() ;command. The number returned is in bytes. Function AvailSysMem() bank = CreateBank (32) GlobalMemoryStatus (bank) mem = PeekInt (bank,12) FreeBank bank Return mem End Function ;This function returns the total physical memory on the user's PC. ;This excludes virtual memory, which can be created on disk, and ;total video memory, which can be accessed using the Blitz TotalVidMem() ;command. The number returned is in bytes. Function TotalSysMem() bank = CreateBank (32) GlobalMemoryStatus (bank) mem = PeekInt (bank,8) FreeBank bank Return mem End Function
ok thanks
Here's how to do the same thing with the CallDLL() command. Mostly this is useful to users of Blitz Basic 2D, which doesn't have access to userlibs.
lpMemoryStatus = CreateBank(32) CallDLL("kernel32.dll","GlobalMemoryStatus",lpMemoryStatus) TotalSysMem = PeekInt (lpMemoryStatus,8) AvailSysMem = PeekInt (lpMemoryStatus,12) FreeBank lpMemoryStatus Print "AvailSysMem = " + AvailSysMem Print "TotalSysMem = " + TotalSysMem WaitKey() End