Symptom
When deploying an application as 64-bit in PowerBuilder, calls to the function GlobalMemoryStatus () will always return 0 for available physical and virtual memory.
Environment
-
Any 64-bit Windows Operating System
-
PowerBuilder
Reproducing the Issue
Call the function GlobalMemoryStatus(), passing an appropriate memory object, and read the values of memobject.ll_availphys and memobject.ll_availvirtual. Both will be 0 on a 64-bit operating system even when running the application in 32-bit.
Cause
The size of the structure passed to the API is 64-bits and this data is not parsed correctly when stored in a 32-bit object's variables.
Solution
-
You can redefine the GlobalMemoryStatus local external function and a new structure to pass to the function:
Subroutine GlobalMemoryStatus (ref os_memorystatusmemorystatus) Library "KERNEL32.DLL" alias for "GlobalMemoryStatusEx"
-
Define a new structure to hold the data:
typeos_memorystatus from structure unsignedlong ul_length unsignedlong ul_memoryload longlong ll_totalphys longlong ll_availphys longlong ll_totalpagefile longlong ll_availpagefile longlong ll_totalvirtual longlong ll_availvirtual longlong ll_AvailExtendedVirtual end type
-
Make sure the memory object’s ul_length variable equals 64 before calling GlobalMemoryStatus():
os_memorystatussysmem sysmem.ul_length = 64 GlobalMemoryStatus(sysmem)