#include <iostream>
#include<vector>
using namespace std;
vector<int> ver;
int pushData(int n)
{
for(int i=0;i<n;i++)
{
ver.push_back(i);
}
}
我想从JS调用pushData函数并将一些数据推送到向量“ver”并稍后使用它。
请解释如何使用 WebAssembly 来做到这一点。
我正在做像你一样的事情。在我看来,在 WASM 中使用 STL 是非常困难的。
我的解决方案是创建一个模拟向量。Wasm仅支持int32、int64、float32和float64,并且wasm的地址与其他进程不同。因此直接导入库是不可行的。您可以通过代理或转换来调用库函数。或者您可以自己编写。
在这种情况下,vector
不能直接导入。您可以创建一个名为vector
,并实施push_back
功能。
class vector{
public:
bool push_back(int i){
// do something
}
int& at(uint index){
// do something
}
private:
int* int_ptr;
}
更多详情请点击此处https://aransentin.github.io/cwasm/ https://aransentin.github.io/cwasm/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)