Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

32
LINES

< > BotCompany Repo | #1029251 // ManagedIntObjects_v1_virtual - works on IIntMemory instead of int[]

JavaX fragment (include) [tags: use-pretranspiled]

Uses 11335K of libraries. Click here for Pure Java version (5408L/33K).

// Yeah this subclass relationship is nasty
sclass ManagedIntObjects_v1_virtual extends ManagedIntObjects_v1 {
  replace Addr with int.
  replace BoxedAddr with Int.
  
  IIntMemory vmem;
  
  *(IIntMemory *vmem) { mem = null; }
  
  public long size() { ret (int) vmem.size(); }
  public int get(Addr i) { ret vmem.get(i); }
  public void set(Addr i, int val) { vmem.set(i, val); }
  
  int[] readIntArray(BoxedAddr ptr) {
    if (ptr == 0) null;
    int n = get(ptr++);
    int[] a = new[n];
    for i to n:
      a[i] = get(ptr+i);
    ret a;
  }
  
  void fillMem(int start, int end, int value) {
    for (int i = start; i < end; i++)
      set(i, value);
  }
  
  void memCopy(int src, int dest, int n) {
    for i to n:
      set(dest+i, get(src+i));
  }
}

Author comment

Began life as a copy of #1029226

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1029251
Snippet name: ManagedIntObjects_v1_virtual - works on IIntMemory instead of int[]
Eternal ID of this version: #1029251/10
Text MD5: f7461e7953c95c0ac18b4ac50a50360c
Transpilation MD5: 516faf139c1a35628482014a5ce2fd07
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-25 07:51:55
Source code size: 793 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 279 / 583
Version history: 9 change(s)
Referenced in: [show references]