"Invalid Heap Size" error when writing ASM.js by hand

447 views Asked by At

I'm trying to write some performance intensive js code so I figured I'd give writing asm.js a try. However whenever I try to instantiate my module with a heap I get the following error in both Node.js and latest Chrome:

Linking failure in asm.js: Invalid heap size

Here is a minimal set of asm code which reproduces the error. Here's the module definition:

function myModule(stdlib, foreign, heap) {
    "use asm"

    var heap8 = new stdlib.Uint8Array(heap);
    function init() {

        heap8[0] = 100;

    }

    return { init : init };

}

And here's how I instantiate it:

const buffer = new Uint8Array( 80 );
const result = myModule(window, null, buffer.buffer);
result.init();

Why am I getting an invalid heap size error?

Thanks!

0

There are 0 answers