试图创建一个大小为从JS导入的变量的数组似乎不起作用。例如:
AssemblyScript:
export declare arrSize: u32
const arr = new Uint32Array(arrSize)
export function init (): void {
unchecked(testArr[0]) = 1
store<u32>(0, unchecked(testArr[0]))
}联署材料:
const memory = new WebAssembly.Memory({ initial: 1 })
WebAssembly.instantiateStreaming(fetch('module.wasm'), {
env: { memory },
index: { arrSize: 2 }
}).then(module => {
const { init } = module.instance.exports
init()
const arr = new Uint32Array(memory.buffer, 0, 2)
console.log(arr)
})然而,如果我在const arr = new Uint32Array(2)文件中更改了AssemblyScript,它就能工作。
是否有一种方法可以在WebAssembly模块中动态调整本地数组的大小?
发布于 2021-01-13 19:02:26
这样做是可行的:
export declare const count: i32;
const arr = new Array<i32>(count);
export function getCount(): i32 {
return arr.length;
}在WebAssembly.instantiate的imports对象中,您应该拥有:
{
index: {
count: 22
}
}如果您的汇编脚本文件名为index.ts
https://stackoverflow.com/questions/65667702
复制相似问题