To get as close as possible to raw memory from JavaScript we have to use WebGL typed arrays. It’s easy for a JIT to befriend those guys and optimize the hell out of reads and writes, because they have a nice semantics for their backing stores: no nasty holes leading to prototype lookups, all elements have known primitive type and no boxing is required.

var blocks = [];  function Block(size) {     this.size = size;     this.buf = new ArrayBuffer(this.size);     this.i32 = new Int32Array(this.buf);     this.f64 = new Float64Array(this.buf); }  function malloc(N) {     if (blocks[N] && blocks[N].length) return blocks[N].pop();     return new Block(N); }  function free(addr) {     (blocks[addr.size] || (blocks[addr.size] = [])).push(addr); }

This is a very naïve implementation (I would even say parody) of the famous malloc&free duo. It does not try to optimize memory usage at all but it is perfect for our demonstration.

I need to rewrite my Javascript Opendap server using WebGL typed arrays.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s