You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I'm playing with mmap, and because of that I need to manipulate the memory from Wazero. Currently, I have the following code:
// internalWazeroMemoryInstance is a private struct in wazero
type internalWazeroMemoryInstance struct {
Buffer []byte
Min, Cap, Max uint32
mux sync.RWMutex
}
// wasm.Memory is private, we need to use unsafe
_hostMemoryInstance := mod.Memory()
hostMemoryInstance := (*[2]*internalWazeroMemoryInstance)(unsafe.Pointer(&_hostMemoryInstance))[1]
hostMemoryInstance.mux.Lock()
defer hostMemoryInstance.mux.Unlock()
//...
// redefine wazero memory (including capacity)
hostMemoryInstance.Buffer = mem
hostMemoryInstance.Cap = f.pages
Describe the solution you'd like
Maybe a simpler interface/struct of Memory, which could be:
type Memory struct {
Buffer []byte
Grow func(pages int) int
}
Or, using Interface:
type MemoryInterface interface {
Buffer() []byte
Grow(page int) int
}
In that case, anyone can have any custom implementation, which will be called when "Grow" (fixing #1150), and also provides one way to implement Buffer using mmap, arenas (golang/go#51317) or anything else.
The current Memory implementation is very large, and contains a lot of Read* and such, which makes very hard to implement and, since we have []byte by default, anyone can read from that (so ReadFloat32Le can just take from .Buffer()).
Describe alternatives you've considered
Using unsafe, which works, but it's unsafe and unstable.
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
I'm playing with mmap, and because of that I need to manipulate the memory from Wazero. Currently, I have the following code:
https://github.com/inkeliz/karmap/blob/b0ed8241fbc27fd4f3b915bdba8da9ebec17f8ba/wazero/wasmkarmap/karmap.go#L62-L74
That is necessaty because I need to modify the
Buffer
and alsoCap
. And I need to do it for two reasons:Describe the solution you'd like
Maybe a simpler interface/struct of Memory, which could be:
Or, using Interface:
In that case, anyone can have any custom implementation, which will be called when "Grow" (fixing #1150), and also provides one way to implement
Buffer
using mmap, arenas (golang/go#51317) or anything else.The current Memory implementation is very large, and contains a lot of
Read*
and such, which makes very hard to implement and, since we have[]byte
by default, anyone can read from that (so ReadFloat32Le can just take from .Buffer()).Describe alternatives you've considered
Using unsafe, which works, but it's unsafe and unstable.
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: