var myStuff = ; myStuff = 42; myStuff = true; myStuff = "Strings";
var buffer = new ArrayBuffer(256); var i32 = new Int32Array(buffer); i32 = 1; i32 = 3; i32 = i32 + i32;
In this example, an array buffer of 256 bytes is allocated. A view, rendering the data as an array of 32bit integers, is then projected onto that buffer. Because the memory is continuous and the types are known, the operations (such as add in this case) perform much faster.
J2V8 2.2 supports the creation of Typed Arrays. You can even access the contents of the arrays, in bulk, from Java using the getIntsMethod (getDoubles and getBoolean for doubles and booleans).
V8 v8 = V8.createV8Runtime(); V8Array result = v8.executeArrayScript("var buffer = new ArrayBuffer(256);\n" + "var i32 = new Int32Array(buffer);\n" + "i32 = 1;\n" + "i32 = 3;\n" + "i32 = i32 + i32;\n" + "i32;"); int ints = result.getInts(0, 3); System.out.println("Result: " + ints + ", " + ints + ", " + ints); result.release(); v8.release();
64 Bit Windows Support
J2V8 now supports 64 bit Windows. The binaries have pushed to Maven Central and can be consumed using the following dependency.
com.eclipsesource.j2v8 j2v8_win32_x86_64 2.2.1 compile
For more news about J2V8, follow me on Twitter.