Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I pass a complex type to a function? #41

Open
furesoft opened this issue Oct 31, 2021 · 3 comments
Open

How can I pass a complex type to a function? #41

furesoft opened this issue Oct 31, 2021 · 3 comments
Labels

Comments

@furesoft
Copy link

No description provided.

@RyanLamansky
Copy link
Owner

Allocate it's structure in memory space, then pass the address of that memory to the function. This is basically how pointers or references work in other languages.

Alternatively, use separate parameters for each component of that object and reconstruct it within the function. This is how .NET passes structs to functions.

@Astn
Copy link

Astn commented Nov 2, 2021

Maybe this has been answered somewhere else, so sorry if asking again.

Does this mean that there is no way to pass data without doing a full copy?
With Pinvoke we can send Pinned pointers. Is there anything like that?
If not is there some way that you could define the Memory Space so it has access to shared memory some way?
Maybe with https://docs.microsoft.com/en-us/dotnet/api/system.buffers.memorymanager-1?view=net-5.0

I'm really interested in an effectively zero copy path to calling functions that can manipulate, or return objects (by pointer is fine)

@RyanLamansky
Copy link
Owner

You can do that by importing memory. The provider of that memory can hold on to the reference and directly access any of its contents even after the WASM has started operating. Managing memory shared inside and outside of WASM requires care, but enables zero-copy paths that use pointers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants