The function getFreePhysMemNet[] returns the amount of free physical memory in Kb. This works both under 32bit and 64 bit Windows butmethod is 30 times slower than direct calling of the GlobalMemoryStatusEx function of kernel32.dll. Here which is the code foravailiable both on 32 bit and 64 bit Windows systems (checked under Windows 7 x64). Here is the code:
Needs["NETLink`"]; getFreePhysMem::internalError = "globalMemoryStatusEx[memorystatusex] has not returned True."; If[$OperatingSystem === "Windows" && $SystemWordLength === 32, memorystatusex = Symbol["LoadedNETTypes"][]; globalMemoryStatusEx = Symbol["DefineDLLFunction"][ "[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)] public class MEMORYSTATUSEX {public uint dwLength; public uint dwMemoryLoad; public ulong ullTotalPhys; public ulong ullAvailPhys; public ulong ullTotalPageFile; public ulong ullAvailPageFile; public ulong ullTotalVirtual; public ulong ullAvailVirtual; public ulong ullAvailExtendedVirtual; public MEMORYSTATUSEX() {this.dwLength = (uint) Marshal.SizeOf(typeof( MEMORYSTATUSEX ));}} [return: MarshalAs(UnmanagedType.Bool)] [DllImport(\"kernel32.dll\", CharSet=CharSet.Auto, \ SetLastError=true)] public static extern bool GlobalMemoryStatusEx([In, Out] \ MEMORYSTATUSEX lpBuffer);"]; memorystatusex = Complement[Symbol["LoadedNETTypes"][], memorystatusex][[1, 1]]; memorystatusex = memorystatusex <> "+MEMORYSTATUSEX"; memorystatusex = Symbol["NETNew"][memorystatusex]; getFreePhysMem[] := If[TrueQ[globalMemoryStatusEx[memorystatusex]], memorystatusex@ullAvailPhys, Message[getFreePhysMem::internalError]; Abort[]; $Failed]];$OperatingSystem === "Windows", memorystatusex = Symbol["LoadedNETTypes"][]; globalMemoryStatusEx = Symbol["DefineDLLFunction"][ "[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)] public class MEMORYSTATUSEX {public uint dwLength; public uint dwMemoryLoad; public ulong ullTotalPhys; public ulong ullAvailPhys; public ulong ullTotalPageFile; public ulong ullAvailPageFile; public ulong ullTotalVirtual; public ulong ullAvailVirtual; public ulong ullAvailExtendedVirtual; public MEMORYSTATUSEX() {this.dwLength = (uint) Marshal.SizeOf(typeof( MEMORYSTATUSEX ));}} [return: MarshalAs(UnmanagedType.Bool)] [DllImport(\"kernel32.dll\", CharSet=CharSet.Auto, \ SetLastError=true)] public static extern bool GlobalMemoryStatusEx([In, Out] \ MEMORYSTATUSEX lpBuffer);"]; memorystatusex = Complement[Symbol["LoadedNETTypes"][], memorystatusex][[1, 1]]; memorystatusex = memorystatusex <> "+MEMORYSTATUSEX"; memorystatusex = Symbol["NETNew"][memorystatusex]; getFreePhysMem[] := If[TrueQ[globalMemoryStatusEx[memorystatusex]], memorystatusex@ullAvailPhys, Message[getFreePhysMem::internalError]; Abort[]; $Failed]];