I am writing a GPU database and looking at using javascript as the language 
to query data and node.js looks ideal for sending and receiving binary 
data. I have been writing a node addon as I have written it in C++. However 
I have problem with my node.js addon as my c++ objects are not being 
destructed when I am not explicitly using the new operator. If I am using 
the new operator, it's fine, it's just when a call a method that creates a 
new method - like copy(), etc.

Please could I get some advice.

Let me show the code that frees GPU memory correctly, the code doesn't free 
correctly and my node.js addon implementation so far.

1. Code that correctly frees GPU memory

This piece of code correctly frees the GPU memory by calling the object 
destructor, which makes a call to free the GPU memory:


*var gpudb = require('./build/Release/gpudb');*

*var n = 1000000;*
*for (var i = 0; i < 10000; ++i) {*
* var col = new cream.GpuArray(n);*
*}*

However, this piece of code doesn't call the objects' destructor. 


*var gpudb = require('./build/Release/gpudb');*

*var n = 1000000;*
*var col = new cream.GpuArray(n);*
*for (var i = 0; i < 10000; ++i) {*
*        var copyOfCol = col.copy();*
*}*

Now, here's the functions for the constructor and copy function 
respectively.

*Handle<Value> GpuVector::New(const Arguments& args) {*
*  HandleScope scope;*

*  if (args.IsConstructCall()) {*
*    // Invoked as constructor: `new **GpuVector**(...)`*
*    int value = args[0]->IsUndefined() ? 0 : args[0]->NumberValue();*
    *GpuVector*** obj = new **GpuVector**(value);*
*    obj->Wrap(args.This());*
*    return args.This();*
*  } else {*
*    // Invoked as plain function `**GpuVector**(...)`, turn into construct 
call.*
*    const int argc = 1;*
*    Local<Value> argv[argc] = { args[0] };*
*    return scope.Close(constructor->NewInstance(argc, argv));*
*  }*
*}*

*Handle<Value> GpuArray::Copy(const Arguments& args) {*
* HandleScope scope;*

* GpuArray* in = ObjectWrap::Unwrap<**GpuVector**>(args.This());*
* GpuArray* out = new GpuArray(in); // creates new gpu memory slot and 
copies the data over*

*        out->Wrap(args.This());*
*        return args.This();*
*}*

 

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to