Comments (1)
I tried to use pass float* and size_t* to wasm module. After using wasm_runtime_module_malloc(). I found that the absolute address is different. Here is my cpp code(I only copyed the part which has problem)
float* test_input; test_input=new float[5]{1.0,2.0,3.0,4.0,5.0}; std::cout<<test_input<<std::endl; uint32_t buffer_for_wasm_test_input=wasm_runtime_module_malloc(wasm_module_inst,sizeof(float)*5, (void**)&test_input); std::cout<<test_input<<std::endl; void* input=wasm_runtime_addr_app_to_native(wasm_module_inst, buffer_for_wasm_test_input); std::cout<<input<<std::endl; size_t* shape_input=new size_t[3]{1,1,5}; std::cout<<shape_input<<std::endl; uint32_t buffer_for_wasm_shape_input=wasm_runtime_module_malloc(wasm_module_inst,sizeof(size_t)*3,(void**)&shape_input); std::cout<<shape_input<<std::endl; void* test=wasm_runtime_addr_app_to_native(wasm_module_inst, buffer_for_wasm_shape_input); std::cout<<test<<std::endl;And the result is that
0x5605cbb7e420 0x7f4e9fa10610 0x7f4e9fa10610 0x5605cbb7e440 0x7f4e9fa10630 0x7f4e9fa10630
I am wondering why after using the wasm_runtime_module_malloc(), the pointer address is different. And if I want them to be same ,how to do that? Thank you!
Hi, the wasm_runtime_module_malloc
returns both the offset in the linear memory (buffer_for_wasm_test_input) and the absolute address of that offset in native (test_input = linear_base_addr + buffer_for_wasm_test_input), and you can convert them to each other by calling wasm_runtime_addr_app_to_native/wasm_runtime_addr_native_to_app.
I suppose you want to module_malloc the memory, and put the data into it, maybe you can:
float test_input_buf[5] = {1.0,2.0,3.0,4.0,5.0};
float* test_input = NULL;
uint32_t buffer_for_wasm_test_input=wasm_runtime_module_malloc(wasm_module_inst,sizeof(float)*5, (void**)&test_input);
if (buffer_for_wasm_test_input == 0)
return error;
memcpy(test_input, test_input_buf, sizeof(float) * 5);
...
from wasm-micro-runtime.
Related Issues (20)
- Run wamr with zephyr on nrf5340 board unsuccessfully. HOT 2
- Does WAMR support wasi preview2? HOT 2
- zephyr: unable to compile with `WAMR_BUILD_LIBC_WASI` flag. HOT 3
- Access reference objects in native function HOT 5
- Optional memory sandboxing HOT 5
- default WASM_STACK_GUARD_SIZE seems too small for linux HOT 16
- StackClashProtector for OS_ENABLE_HW_BOUND_CHECK
- OS_ENABLE_HW_BOUND_CHECK can cause resource leak HOT 4
- `fd_advise` always succeeds
- per-host function override of native stack requirement HOT 7
- argv_buf on-stack array sizes might have a room to improve
- How to use coroutines in wasm? HOT 2
- Add ability to get import and export information from wasm_export interface HOT 2
- An unexpected behavior in multiple modes HOT 2
- Unexpected Execution HOT 2
- WAMR throw OOB exception in LLVM-JIT mode while not in Fast-JIT mode HOT 3
- Error occurs when calling native function with local variable in AOT mode? HOT 8
- Heap Buffer Overflow Inside "wasm_loader_check_br" Function HOT 3
- Out-of-Bound Memory Read inside "block_type_get_arity" Function HOT 3
- Error compiling wamr 2.0.0 for Windows. Error: invalid numeric argument '/Wextra' HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wasm-micro-runtime.