Skip to content

Commit

Permalink
Notify V8 GC of libvips cache size #21
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Aug 26, 2014
1 parent 0d89131 commit bac367b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/sharp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ class ResizeWorker : public NanAsyncWorker {

if (baton->buffer_out_len > 0) {
// Buffer
argv[1] = NanNewBufferHandle((char *)baton->buffer_out, baton->buffer_out_len);
argv[1] = NanNewBufferHandle(static_cast<char*>(baton->buffer_out), baton->buffer_out_len);
g_free(baton->buffer_out);
argv[2] = info;
} else {
Expand Down Expand Up @@ -730,7 +730,12 @@ NAN_METHOD(cache) {

// Set cache memory limit
if (args[0]->IsInt32()) {
vips_cache_set_max_mem(args[0]->Int32Value() * 1048576);
int newMax = args[0]->Int32Value() * 1048576;
int oldMax = vips_cache_get_max_mem();
vips_cache_set_max_mem(newMax);

// Notify the V8 garbage collector of delta in max cache size
NanAdjustExternalMemory(newMax - oldMax);
}

// Set cache items limit
Expand Down Expand Up @@ -767,9 +772,14 @@ extern "C" void init(Handle<Object> target) {
NanScope();
vips_init("sharp");
AtExit(at_exit);

// Set libvips operation cache limits
vips_cache_set_max_mem(100 * 1048576); // 100 MB
vips_cache_set_max(500); // 500 operations

// Notify the V8 garbage collector of max cache size
NanAdjustExternalMemory(vips_cache_get_max_mem());

// Methods available to JavaScript
NODE_SET_METHOD(target, "metadata", metadata);
NODE_SET_METHOD(target, "resize", resize);
Expand Down

0 comments on commit bac367b

Please sign in to comment.