-
-
Notifications
You must be signed in to change notification settings - Fork 670
[Question] Best way to manage a buffer #774
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
Comments
@jtenner made: https://github.com/as2d/as2d, so he'd be the better one to answer this. But the big take away from his solution to this problem was to queue up mutations and then flush them all at once. Here is his article about it: https://dev.to/jtenner/optimizing-canvasrenderingcontext2d-function-calls-using-assemblyscript-4i4b Glad to hear things are going well so far! |
Thanks for the links! Im not too concerned about how fast the render methods will be called so I don't think a queue will be necessary for my use case yet. I'm more concerned about managing a buffer that will be changing in size each time its used (and not knowing how large it could get). I think for now I will just keep the buffer around and increase the size as needed. Thanks again! |
This doesn't look like it will work btw: let pointer = module.allocateMemory(length);
let wasmArray = new Uint8ClampedArray(module.memory.buffer, pointer, jsArray.length);
wasmArray.set(jsArray); Here, Other than that, the most efficient way to work with explicitly resize-able memory segments is using |
Thanks @dcodeIO. I was following examples from this issue and never released the pointer was pointing to something else. Everything seems to be working with my current implementation though. Ill try playing around with |
Hello!
I'm pretty new to Web Assembly and managing memory and just wanted to ask what the best way to manage this scenario is.
My module will be processing pixels in a Uint8ClampedArray (from a canvas).
Right now my set up is as follows (which is working great):
My issue is that
renderJS()
will be called multiple times throughout the lifecycle, but each time the canvas will probably be a different size and have a different amount of pixels, meaning the buffer length would have to change.In this scenario, should I be destroying the buffer and recreating it each render? Or is there a better way to do this?
Thanks so much for the help, i've been having a lot of fun using this project and am learning a lot.
The text was updated successfully, but these errors were encountered: