Skip to content

Mutating the same TypedArray on either side of the JS or WASM fence #850

@michaeltheory

Description

@michaeltheory

Hi,

Thanks for all the work on AssemblyScript -- the tooling is fantastic.

I'm aware there are other issues that ask a similar question, but unfortunately I couldn't find a specific answer, so I'm hoping for some clarification.

My search started in this thread but what I'm finding hard to follow is that OP seems to be trying to take two steps at once, both sharing memory and packing different data sets into it.

I did notice this comment which appears to be exactly what I want to do. An array that can be mutated and read from on either side WASM/JS.

I followed some links to this repo which sort of worked after I used what appeared to be the new API in assemblyscript/lib/loader with __allocArray and __get(X)Array instead. The issue here though is that __get appears to be creating a new typed array, or atleast view of it. I also have to call __get in JS every time the data has been mutated in AS, which isn't possible in my use case.

The most promising avenue I found was this pull request but I wanted to ask this before trying to piece that together, because it seems like the API might have changed in the last year since those questions were asked.

My use case is I have a 3D engine and I want to do the expensive work in WASM. For example, A Vector3 class has a Float32Array with 3 floats. I would like to mutate it in JS, but then allow AS to have a reference to and be able to use those 3 floats in computation.

Could someone guide me to the best solution?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions