I am writing a GPU database and consider using javascript as a language for querying against using node.js.
I wrote the node addon since I wrote a GPU database in C ++. However, I have a problem with my node.js addon, because my C ++ objects are not destroyed, but only when I explicitly do not use the new operator. If I use a new operator, this is normal, just when calling a method that creates a new method - for example, copy (), etc. I use V8 :: AdjustAmountOfExternalAllocatedMemory (size ()) as an indication to V8 that I have allocated external memory (on the GPU).
Please, I can consult.
1. Code that correctly frees up GPU memory
This piece of code correctly frees the GPU memory by invoking the destructor of the object that makes the 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 gpudb.GpuArray(n);
}
2. However, this piece of code does not call the object destructor to free the GPU memory.
var gpudb = require('./build/Release/gpudb');
var n = 1000000;
var col = new gpudb.GpuArray(n);
for (var i = 0; i < 10000; ++i) {
var copyOfCol = col.copy();
}
3. Now here are the functions for the constructor and the copy function, respectively.
Handle<Value> GpuVector::New(const Arguments& args) {
HandleScope scope;
if (args.IsConstructCall()) {
int value = args[0]->IsUndefined() ? 0 : args[0]->NumberValue();
GpuVector* obj = new GpuVector(value);
obj->Wrap(args.This());
return args.This();
} else {
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);
out->Wrap(args.This());
return args.This();
}
source
share