Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interop.Reference returns undefined value #134

Open
DeepakArora76 opened this issue Nov 20, 2021 · 1 comment
Open

interop.Reference returns undefined value #134

DeepakArora76 opened this issue Nov 20, 2021 · 1 comment

Comments

@DeepakArora76
Copy link

Hi everyone,

I need your help to understand why the vmStatRef.value.free_count in the below code returns undefine value.

I am using NativeScript 8.1. The platform is iOS.

  "devDependencies": {
    "@nativescript/android": "~8.1.1",
    "@nativescript/core": "~8.1.4",
    "@nativescript/ios": "~8.1.0",
    "@nativescript/types": "~8.1.1",
    "@nativescript/webpack": "^3.0.0",
    "prompt": "^1.2.0",
    "rimraf": "^3.0.2",
    "semver": "^7.3.5",
    "ts-node": "^10.4.0",
    "ts-patch": "^1.4.4",
    "tslint": "^6.1.3",
    "typescript": "~4.4.4"
  }

The git repository is https://github.com/DeepakArora76/nativescript-dna-deviceinfo

Here is a 64-bit implementation

  static freeMemory(): number {
    const KERN_SUCCESS = 0;
    const HOST_VM_INFO = 2;
    const hostSize = new interop.Reference(interop.sizeof(vm_statistics64)/interop.sizeof(interop.types.int64));
    const hostPort = mach_host_self();

    const pageSize = new interop.Reference(0);
    host_page_size(hostPort, pageSize);

    const vmStat = interop.alloc(interop.sizeof(vm_statistics64));

    let freeMem = -1;
    if (host_statistics64(hostPort, HOST_VM_INFO, vmStat, hostSize) === KERN_SUCCESS) {
      const vmStatRef = new interop.Reference<vm_statistics64>(vm_statistics64, vmStat);
      freeMem = vmStatRef.value.free_count * pageSize.value;
    }
    return freeMem;
  }

I also tried vm_statistics instead of vm_statistics64 and that too failed as well!

32-bit implementation

  static freeMemory(): number {
    const KERN_SUCCESS = 0;
    const HOST_VM_INFO = 2;
    const hostSize = new interop.Reference(interop.sizeof(vm_statistics)/interop.sizeof(interop.types.int32));
    const hostPort = mach_host_self();

    const pageSize = new interop.Reference(0);
    host_page_size(hostPort, pageSize);

    const vmStat = interop.alloc(interop.sizeof(vm_statistics));

    let freeMem = -1;
    if (host_statistics(hostPort, HOST_VM_INFO, vmStat, hostSize) === KERN_SUCCESS) {
      const vmStatRef = new interop.Reference<vm_statistics>(vm_statistics, vmStat);
      freeMem = vmStatRef.value.free_count * pageSize.value;
    }
    return freeMem;
  }
@rigor789 rigor789 transferred this issue from NativeScript/ios-jsc Nov 20, 2021
@DeepakArora76
Copy link
Author

DeepakArora76 commented Nov 23, 2021

@rigor789 A similar issue is #103

I would highly appreciate it if these issues could be prioritized. I hope we do not have to wait for many months to see a fix.

If there is a workaround for it, please suggest it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant