New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pointer#toBuffer throws "TypeError: First argument must be a Buffer" #48
Comments
Can you give me a more complete example that reproduces the error? |
var ffi = require("./node-ffi");
var arr = [];
for(i=0;i<1000000;++i)
{
var ptr = new ffi.Pointer(100+i%1000);
ptr.toBuffer();
arr.push([ptr,ptr.toBuffer()]);
} output
I think create Buffer in c++,you should use Handle<Value> NewNodeBuffer(void * buf,int len)
{
v8::HandleScope scope;
node::Buffer * slowBuffer = node::Buffer::New((char*)buf,len);
assert(!slowBuffer->handle_.IsEmpty());
Local<Object> global = v8::Context::GetCurrent()->Global();
Local<Value> bv = global->Get(String::NewSymbol("Buffer"));
assert(bv->IsFunction());
Local<Function> b = Local<Function>::Cast(bv);
Handle<Value> argv[3] = { slowBuffer->handle_, Integer::New(len) , Integer::New(0) };
Handle<Object> instance = b->NewInstance(3, argv);
return scope.Close(instance);
} If I change |
Interesting. Indeed, your script crashes for me, and the proposed fix fixes that. But I've come to realize that there's absolutely no benefit in doing the "SlowBuffer -> Buffer" dance, so I'm gonna just return the |
Hi, Sorry to hijack this thread, but I was looking for information about the "SlowBuffer->Buffer dance" and found your comment about not having any benefit. Why is that? Is this a general comment or it only applies to this commit? Thanks! |
@santigimeno It applies to any time you create a SlowBuffer instance, which is what we were doing already. Wrapping it in a JS-buffer doesn't magically make it any faster, it's just another object wrapping the SlowBuffer we already created. |
This doesn't occur everytime, seldom.
Here is the code:
and output:
The text was updated successfully, but these errors were encountered: