Create my own memory

This commit is contained in:
Surma
2019-01-24 16:33:03 -05:00
parent fdbc0932e4
commit 41f085438b
3 changed files with 6 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
{
"name": "rotate",
"scripts": {
"build": "mv rotate.{as,ts} && asc rotate.ts -b rotate.wasm --validate -O3 && mv rotate.{ts,as}"
"build": "mv rotate.{as,ts} && asc rotate.ts -b rotate.wasm --validate -O3 --importMemory && mv rotate.{ts,as}"
},
"devDependencies": {
"assemblyscript": "github:AssemblyScript/assemblyscript"

Binary file not shown.

View File

@@ -11,8 +11,12 @@ export async function rotate(
const numPagesNeeded = Math.ceil(bytesPerImage * 2 / (64 * 1024));
const { instance } = (await (WebAssembly as any).instantiateStreaming(
fetch(wasmUrl),
{
env: {
memory: new WebAssembly.Memory({ initial: numPagesNeeded }),
},
},
)) as { instance: RotateModuleInstance };
instance.exports.memory.grow(numPagesNeeded);
const view = new Uint8ClampedArray(instance.exports.memory.buffer);
view.set(data.data);