Ingun전인건
Ingun전인건

Reputation: 782

How to use JS TypedArray as Rust BufRead/Read without memory copying?

I need Uint8Array in the form of BufRead or Read.

I could just copy the whole memory using something like to_vec and construct some type of BufRead/Read but I don't want to because the array I'm dealing with can be huge (50~100mb)

I think in order to do that I have to get the address to the mutable continuous memory block, probably in type of *mut [u8]. (I'm not familiar with Rust yet so the syntax might not be right but hope you get the idea). But I can't find the suitable method from Uint8Array doc.

Is it possible? If so, how can I do it?

Upvotes: 1

Views: 343

Answers (1)

kmdreko
kmdreko

Reputation: 60062

You have to copy the data. WebAssembly does not directly have access to memory in the JavaScript environment and must be copied over. Using to_vec is the way to go.

Upvotes: 0

Related Questions