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).
<pre lang="java"> 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(); </pre>
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.
<pre lang="xml"> <dependency> <groupId>com.eclipsesource.j2v8</groupId> <artifactId>j2v8_win32_x86_64</artifactId> <version>2.2.1</version> <scope>compile</scope> </dependency> </pre>
For more news about J2V8, follow me on Twitter.