interop.Reference returns undefined value

Đang mở
#134 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
ios, typescript

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện hành vi được báo cáo liên quan đến interop.Reference, vm_statistics64, vm_statistics, host_statistics64 và host_statistics trên NativeScript iOS 8.1. So sánh dữ liệu vmStat đã được cấp phát với giá trị được cung cấp thông qua vmStatRef.value.free_count. Công việc được xem là hoàn tất khi xác định được lý do trường được trả về là undefined và xác nhận được kết quả bộ nhớ trống hoạt động trên nền tảng được báo cáo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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;
  }
Ngôn ngữ chính
JavaScript
Star
150
Fork
43
Merge trung bình
3 ngày 10 giờ
Pull request đã merge (30 ngày)
22

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của NativeScript/ios

Tất cả issue của NativeScript/ios

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.