Skip to content

Commit

Permalink
n-api: adds function to adjust external memory
Browse files Browse the repository at this point in the history
Changed napi_adjust_external_memory() signature to be more
consistent with the rest of the API

Fixes: nodejs#13928
  • Loading branch information
Chris Young committed Aug 25, 2017
1 parent 77acfd5 commit fd40a07
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 6 additions & 4 deletions doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3394,22 +3394,24 @@ support it:
* If the function is not available, provide an alternate implementation
that does not use the function.

## Garbage Collection
## Memory Management

### napi_adjust_external_memory
<!-- YAML
added: REPLACEME
-->
```C
NAPI_EXTERN int64_t napi_adjust_external_memory(napi_env env,
int64_t change_in_bytes);
NAPI_EXTERN napi_status napi_adjust_external_memory(napi_env env,
int64_t change_in_bytes,
int64_t* result);
```

- `[in] env`: The environment that the API is invoked under.
- `[in] change_in_bytes`: The change in externally allocated memory that is
kept alive by JavaScript objects.
- `[out] result`: The adjusted value

Returns `int64_t` the adjusted value.
Returns `napi_ok` if the API succeeded.

This function gives V8 an indication of the amount of externally allocated
memory that is kept alive by JavaScript objects (i.e. a JavaScript object
Expand Down
3 changes: 1 addition & 2 deletions test/addons-napi/test_general/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,4 @@ assert.strictEqual(test_general.finalizeWasCalled(), false,
'finalize callback was not called upon garbage collection');

// test napi_adjust_external_memory
const adjustedValue = test_general.testAdjustExternalMemory();
assert.strictEqual(typeof adjustedValue, 'number');
assert.strictEqual(typeof test_general.testAdjustExternalMemory(), 'number');

0 comments on commit fd40a07

Please sign in to comment.