How to use memset
in jsctypes. There no DLL for it. I searched/scoured js ctype codes but couldn't find an example to rip.
Asked
Active
Viewed 103 times
0
1 Answers
1
If you just want to memset
an array to zero-bytes, then I have "Good news, everyone": js-ctypes will initialize new arrays to zero.
Otherwise it would be probably easiest to just create a typed array, initialize it, and create a pointer to it.
Apparently you can also set array elements directly on a ctypes array these days (provided the array type has a known size)...
// 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])"
-
Are you kidding me, thats it? Dude I got some fundamental issues, i searched the world..... How can I learn to be a js-ctype expert? :( – Noitidart Jun 28 '14 at 12:06
-
First become a C and C++ expert, and then Javascript expert. The dive into (js-)ctypes by trial and error. The rest afterwards is easy :p. Nah, I wouldn't call myself an expert to be honest, but "knowledgeable" maybe. – nmaier Jun 28 '14 at 12:10
-
:( i'll try to start with learning about those ctypes arrays they are totally different than what I'm used to i think. – Noitidart Jun 28 '14 at 12:12
-
i think im reaching js-ctypes expert status :D i just deployed my first addon heavily relying on jsctypes, it needs perf improvment but man these comments made me reminisce! Check it out! https://addons.mozilla.org/en-US/firefox/addon/nativeshot/ – Noitidart Aug 01 '15 at 16:16