Binary array using V8 engine

夙愿已清 提交于 2019-12-06 12:01:32

The most efficient way is to use external arrays:

v8::Handle<v8::Object> external_array = v8::Object::New();
external_array->SetIndexedPropertiesToExternalArrayData(ptr, v8::kExternalUnsignedByteArray, 1024);

Good example of external arrays API usage (including lifetime management) can be found in d8.cc: https://github.com/v8/v8/blob/7a0c55bd0d07135ce317f0e95909120eaafd5973/src/d8.cc#L394-L591

like Vyacheslav Egorov already answered

  obj->SetIndexedPropertiesToExternalArrayData(data,
                                           kExternalUnsignedByteArray,
                                           length);

is the right answer. If you need more examples you can check out https://github.com/joyent/node they use lots of v8 functionallity.

just grep -nrw ".*SetIndexedPropertiesToExternalArrayData.*" "." in the /src folder of the project and you will get lots of examples for SetIndexedPropertiesToExternalArrayData

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!