You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The biggest gotcha I've run into between nan v1 and v2 is a change to the Buffer creation methods where ownership of the underlying data is transferred.
In nan v1, the "take ownership" method is NanBufferUse which results in delete[] being called on the data during GC.
In nan v2, the "take ownership" method is Nan::NewBuffer which results in free() being called.
@kkoopa Ah thanks, I read over that one. Is there a nan wrapper for node::smalloc::FreeCallback and node::Buffer::FreeCallback callback? And what is the hint argument?
Activity
winfinit commentedon Aug 6, 2015
converted examples in node-addon-examples may make it a bit easier (pull request is pending, but you can see nan_2.x and nan_1.x here: https://github.com/winfinit/node-addon-examples)
also what helped me a lot is to look through https://github.com/nodejs/nan/tree/master/test
kkoopa commentedon Aug 9, 2015
@rvagg said he was working on one
ivan commentedon Aug 10, 2015
The converter script in #376 (comment) was very helpful for me
mscdex commentedon Aug 13, 2015
+1
eljefedelrodeodeljefe commentedon Aug 20, 2015
Good hint @winfinit . Found everything I needed in the test directory.
lovell commentedon Aug 24, 2015
The biggest gotcha I've run into between nan v1 and v2 is a change to the Buffer creation methods where ownership of the underlying data is transferred.
In nan v1, the "take ownership" method is
NanBufferUsewhich results indelete[]being called on the data during GC.In nan v2, the "take ownership" method is
Nan::NewBufferwhich results infree()being called.JCMais commentedon Aug 24, 2015
@lovell I had a bunch of memory corruption because of this exact change. Took awhile to figure it out.
Docs: note use of free() for disposal of NewBuffer
Docs: note use of free() for disposal of NewBuffer
Docs: note use of free() for disposal of NewBuffer
mathiask88 commentedon Aug 27, 2015
So if I use
newfor memory allocation then I need to useBufferCopyand cannot use the allocated memory block because it is removed withfree()?kkoopa commentedon Aug 27, 2015
Supply a
FreeCallbackthat callsdelete.mathiask88 commentedon Aug 27, 2015
@kkoopa Ah thanks, I read over that one. Is there a nan wrapper for
node::smalloc::FreeCallbackandnode::Buffer::FreeCallback callback? And what is thehintargument?kkoopa commentedon Aug 27, 2015
https://github.com/nodejs/nan/blob/master/nan.h#L1218
The hint argument is user data.
rvagg commentedon Sep 25, 2015
https://nodesource.com/blog/cpp-addons-for-nodejs-v4 here 'tis
JCMais commentedon Sep 25, 2015
Great!