NativeScript / NativeScript/ios

interop.Reference returns undefined value

Open
#134 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
150
Forks
43
Avg merge
3d 10h
Merged PRs (30d)
22

Description

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;
  }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported behavior around interop.Reference, vm_statistics64, vm_statistics, host_statistics64, and host_statistics on NativeScript iOS 8.1. Compare the allocated vmStat data with the value exposed through vmStatRef.value.free_count. Done means identifying why the returned field is undefined and confirming a working free-memory result on the reported platform.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, typescript
Domain
mobile-dev, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.