getSystemMemoryInMegabytes method

  1. @visibleForTesting
int getSystemMemoryInMegabytes()

Implementation

@visibleForTesting
int getSystemMemoryInMegabytes() {
  final memoryInKilobytes = calloc<ULONGLONG>();
  try {
    final result = GetPhysicallyInstalledSystemMemory(memoryInKilobytes);
    if (result != 0) {
      return memoryInKilobytes.value ~/ 1024;
    } else {
      final error = GetLastError();
      throw WindowsException(HRESULT_FROM_WIN32(error));
    }
  } finally {
    free(memoryInKilobytes);
  }
}