wasmer-go icon indicating copy to clipboard operation
wasmer-go copied to clipboard

Write data into the initial memory

Open lowesyang opened this issue 5 years ago • 12 comments

Thanks for proposing a new feature!

Motivation

Write custom data into the initial memory from Go side and let the functions in wasm can use it~

lowesyang avatar May 30 '19 11:05 lowesyang

Can you elaborate or can you give an example of the kind of API you would like to get?

Hywan avatar Jun 03 '19 12:06 Hywan

like wagon providing Process struct to access memory easily. codes

lowesyang avatar Jun 06 '19 02:06 lowesyang

Maybe can add more useful function, like growMemory(), getAllocatedMemory(), getUsedMemory()(maybe unnecessary) and so on.

lowesyang avatar Jun 06 '19 06:06 lowesyang

You have Instance.Memory to access the memory. Then, you can call the Data() method to get a slice over the memory, so that you can read or write things as you want.

Does it cover your initial need?

Hywan avatar Jun 07 '19 10:06 Hywan

(I'll reopen the issue as soon as I receive a response :-))

Hywan avatar Jun 24 '19 09:06 Hywan

Maybe we need an explore Write(bytes) function. I think it's not a good design to modify the underlying bytes array directly.

In Write function, we also need a mutex to implement parallel data reading&writing.

lowesyang avatar Jul 05 '19 03:07 lowesyang

Are you suggesting to implement an io interface, with Reader and Writer? Sounds a good idea to me.

Hywan avatar Jul 05 '19 07:07 Hywan

Yeap, an io interface is also a good idea~

lowesyang avatar Jul 09 '19 07:07 lowesyang

The Instance.Memory seems to not exists anymore, in most recent version, what is the alternative?

It have GetMemory(), but requires an name and requires to be exported, which is not the same as the old one.

inkeliz avatar May 09 '22 17:05 inkeliz

I would like to put this example: https://github.com/tetratelabs/wazero/tree/main/examples/allocation/tinygo and implement it with wasmer-go

I try,but not success,can you give a example?

mougeCM avatar Aug 27 '22 10:08 mougeCM

Hi 👋 I'd be interested in this too. It's supported by the python wasmer here: https://wasmerio.github.io/wasmer-python/api/wasmer/wasmer.html#Memory.uint8_view

This functionality would be useful when working with wasm modules which the wasmer user has no control over the module itself.

For example, this python library based on wasmer wraps OPA modules: https://github.com/a2d24/python-opa-wasm/blob/fb48a89e4b458628d59be58d159cae6aa4615007/opa_wasm/opa_wasm.py#L138 which have no exported functions for setting data.

charlieegan3 avatar Mar 29 '23 14:03 charlieegan3

I would like to put this example: https://github.com/tetratelabs/wazero/tree/main/examples/allocation/tinygo and implement it with wasmer-go

I try,but not success,can you give a example?

成功了吗

isfang avatar Apr 18 '24 05:04 isfang