Skip to content

Is there documentation on how to use JS Interop MemoryView? #102386

Answered by pavelsavara
groogiam asked this question in Q&A
Discussion options

You must be logged in to vote

You can also pass ArraySegment which will GC pin it and you will have long term buffer with IMemoryView interface on JS side. You have to dispose() it, when you are done.

You can also allocate via Marshal.AllocHGlobal and then pass it to JS as IntPtr.
Ideally allocating the buffer once and keep using it to transfer bytes on each chunk of your stream.

Then you can use localHeapViewU8 API to get wasm linear memory.

/**
* Returns a short term view of the WASM linear memory. Don't store the reference, don't use it after await.
*/
localHeapViewU8: () => Uint8Array;

Do it on each chunk, b…

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@pavelsavara
Comment options

Answer selected by pavelsavara
Comment options

You must be logged in to vote
1 reply
@maraf
Comment options

maraf May 21, 2024
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
arch-wasm WebAssembly architecture area-System.Runtime.InteropServices.JavaScript os-browser Browser variant of arch-wasm
3 participants