在不复制的情况下将数组从 C 指针发送到 JS 函数

Sending an array from a C pointer to a JS function without copying

我想以非常高的速率将数据指针发送到 JS 函数(以便在 canvas 上呈现它)。在不复制实际数据的情况下,使用 Emscripten 执行此操作的最佳方法是什么?

以下是正确的吗?

void send(void const * data, unsigned length) {

    EM_ASM({

        var data = new Uint8Array(HEAP8.buffer, [=10=], );
        Module.send();

    }, data, length);

}

问题是它需要在每一帧分配一个 Uint8Array,这不会让垃圾收集器很高兴...:(

根据Emscripten GL implementation, it seems that the best way to achieve what I want is TypedArray#subarray。我想知道它是否会影响垃圾回收。

void send(void const * data, unsigned length) {

    EM_ASM({

        Module.send(HEAPU8.subarray([=10=], [=10=] + ));

    }, data, length);

}