• Unionized arrays anyone?

    //ArrayTrick1.js
    //30 Aug 2016
    //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
    
    var f = new (require("FlashEEPROM"))();
    
    var buff = new ArrayBuffer(16);
    var view   = new Int32Array(buff);
    
    for(var i=0;i<4;i++)view[i]=i*256*256*256+i*100;
    
    //buff and view are unionized
    console.log("buff= ",buff);
    console.log("view= ",view);
    
    buff[0]=5;
    console.log("buff= ",buff);
    console.log("view= ",view);
    
    console.log("write to ROM");
    f.write(21,JSON.stringify(btoa(buff)));
    
    console.log("read from ROM");
    var H=new Int32Array(E.toArrayBuffer(atob(JSON.parse(E.toString(f.read(21))))));
    
    console.log("H= ",H);
    

    The output:

    ent>echo(0);
    buff=  new ArrayBuffer([0, 0, 0, 0, 100, 0, 0, 1, 200, 0, 0, 2, 44, 1, 0, 3])
    view=  new Int32Array([0, 16777316, 33554632, 50331948])
    buff=  new ArrayBuffer([5, 0, 0, 0, 100, 0, 0, 1, 200, 0, 0, 2, 44, 1, 0, 3])
    view=  new Int32Array([5, 16777316, 33554632, 50331948])
    write to ROM
    read from ROM
    H=  new Int32Array([5, 16777316, 33554632, 50331948])er code here
    

    1 Attachment

About