“memset” has no DLL so how ctype it

前端 未结 1 478
耶瑟儿~
耶瑟儿~ 2021-01-17 07:11

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.

相关标签:
1条回答
  • 2021-01-17 07:52

    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])"
    
    0 讨论(0)
提交回复
热议问题