1

I'd like to send a data pointer to a JS function at a very high rate (in order to render it on a canvas). What is the best way to do this with Emscripten, without copying the actual data ?

Is the following correct?

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

    EM_ASM({

        var data = new Uint8Array(HEAP8.buffer, $0, $1);
        Module.send();

    }, data, length);

}

The issue is that it requires an Uint8Array allocation at each frame, which will not make the garbage collector very happy... :(

1 Answer 1

2

According to the Emscripten GL implementation, it seems that the best way to achieve what I want is TypedArray#subarray. I wonder if it might affect the garbage collection, tho.

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

    EM_ASM({

        Module.send(HEAPU8.subarray($0, $0 + $1));

    }, data, length);

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.