-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Store per-instance data? #2491
Comments
Currently you cannot attach data to an |
Oh, forgot to mention that. I'm using the Rust API In most cases, closures are a good way to have per-instance data. But my data will change before every call: the application uses WASM for out of browser plugins, so the application processes data, then call WASM function for each plugin. There is also contextual data, that would be too costly to copy to guest before every call, so the intent is to provide it "on-demand" when the guest requests it. I'm still experimenting: I tested a solution with a global |
Unfortunately I'm not familiar enough with your use case but I suspect a combination of |
It works! I tested two solutions, one based on Thanks @alexcrichton for your help, and the explanations. |
Ok great, glad it worked out! |
Hi,
Is there a way to store data in
instance
?I have a situation where guest calls a host function
get_info_xxx
, and host needs to identify which instance is asking to send the correct data.I tried looking at examples and doc and could not find the solution. Best I can think of is storing data or an identifier by capturing it in the environment of
Func
when creating the Instance, however this is not convenient, since the data is evolving over time (and not known when creating the instance).So, at the moment I'm considering having a global structure to store per-instance data, and give an identifier to instances (captured in callbacks). This may work, but require lots of code (global variables and unsafe access, need for a lock, etc.) that could be avoided if host could just update per-instance data before calling.
Is there a better way of having (dynamic) per-instance data?
Thanks!
The text was updated successfully, but these errors were encountered: