Caching function handles in a struct, is it possible? #1959
Unanswered
IamTheCarl
asked this question in
Q&A
Replies: 1 comment
-
Here's a working example of where I want to employ this. Currently I just get the function every time I need it, which works, but I suspect brings some unnecessary overhead. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So I would like to do the following:
I create a struct which contains an instance, and I cache handles to two functions I call often.
Of course this can't compile, because those two function handles are references to wasm_instance. Self referencing structs are not permitted in Rust, for a good reason of course.
I've experimented with using pins, NonNull, and some unsafe blocks, but I can't solve the lifetimes requirements of the function handles.
The documentation clearly states that using these handles to call, rather than doing instance.exports.get for every call will be faster, so I'd like to do this for my frequently called functions.
So what I'm wondering is... is something like this possible? Or will I be forced to have my instance live outside of the WasmFile struct?
Beta Was this translation helpful? Give feedback.
All reactions