使用V8引擎的二进制数组 [英] Binary array using V8 engine
问题描述
我有一个字节数组定义为
I have an array of bytes defined as
unsigned char ptr = new unsigned char[1024];
fillWithSomething(ptr, 1024);
然后,我需要存储 ptr
Local<中的变量V8 Engine的Array>
变量或另一种V8数据类型。
当前,我将字节数组转换为字符串,以便存储在 Local< String>
变量,但是这种方法对我的应用程序效率不高。
Then, I need to store the ptr
variable in a Local< Array>
variable of V8 Engine or another kind of V8 data type.
Currently, I am converting the array of bytes into a string in order to store in a Local< String>
variable, but this approach is inefficient to my application.
预先感谢。
已更新(感谢Vyacheslav Egorov)
UPDATED (thanks to Vyacheslav Egorov)
我使用外部阵列测试了该解决方案,但是无法在我的node.js服务器代码上使用它。我有以下代码(在我的扩展端C ++上):
I test the solution with an external array but I can't use it on my node.js server code. I have the following code (on my extension side C++):
Handle<Object> array = Object::New();
array->SetIndexedPropertiesToExternalArrayData(getBytes(), kExternalUnsignedByteArray, bytesSize);
return array;
我的问题是,如何使用数组
服务器代码(javascript)中的变量来调用函数 GetIndexedPropertiesExternalArrayData()
。
My question is, How I can use the array
variable in my server code (javascript) to call the function GetIndexedPropertiesExternalArrayData()
.
再次感谢
推荐答案
最有效的方法是使用外部数组:
v8::Handle<v8::Object> external_array = v8::Object::New();
external_array->SetIndexedPropertiesToExternalArrayData(ptr, v8::kExternalUnsignedByteArray, 1024);
可以在 d8.cc
: https ://github.com/v8/v8/blob/7a0c55bd0d07135ce317f0e95909120eaafd5973/src/d8.cc#L394-L591
这篇关于使用V8引擎的二进制数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!