如何在jsctypes中使用memset
。它没有DLL。我搜索/搜索了js ctype代码,但找不到一个rip的例子。
答案 0 :(得分:1)
如果你只想memset
一个数组为零字节,那么我有“好消息,每个人”:js-ctypes会将新数组初始化为零。
否则,创建一个类型化数组,初始化它和create a pointer to it可能是最简单的。
显然你现在也可以直接在ctypes数组上设置数组元素(前提是数组类型的已知大小)......
// Note that size is the number of array elements to set,
// not the number of bytes.
function memset(array, val, size) {
for (var i = 0; i < size; ++i) {
array[i] = val;
}
}
var a = ctypes.uint8_t.array()(10);
memset(a, 0xde, a.length);
console.log(a.toSource());
// "ctypes.uint8_t.array(10)([222, 222, 222, 222, 222, 222, 222, 222, 222, 222])"