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.

Resolution

  1. 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"

  1. Define a new structure to hold the data:

typeos_memorystatus from structure

    unsignedlongul_length

    unsignedlongul_memoryload

    longlongll_totalphys

    longlongll_availphys

    longlongll_totalpagefile

    longlongll_availpagefile

    longlongll_totalvirtual

    longlongll_availvirtual

    longlongll_AvailExtendedVirtual

end type

  1. Make sure the memory object’s ul_length variable equals 64 before calling GlobalMemoryStatus():

os_memorystatussysmem

sysmem.ul_length = 64

GlobalMemoryStatus(sysmem)

1
0