napi_adjust_external_memory


NAPI_EXTERN napi_status napi_adjust_external_memory(node_api_basic_env env,
                                                    int64_t change_in_bytes,
                                                    int64_t* result); 
  • [in] env:调用 API 的环境。

    ¥[in] env: The environment that the API is invoked under.

  • [in] change_in_bytes:由 JavaScript 对象保持活动状态的外部分配内存的变化。

    ¥[in] change_in_bytes: The change in externally allocated memory that is kept alive by JavaScript objects.

  • [out] result:调整后的值。此值应反映包含给定 change_in_bytes 的外部内存总量。不应依赖返回值的绝对值。例如,实现可以对所有插件使用单个计数器,或者对每个插件使用一个计数器。

    ¥[out] result: The adjusted value. This value should reflect the total amount of external memory with the given change_in_bytes included. The absolute value of the returned value should not be depended on. For example, implementations may use a single counter for all addons, or a counter for each addon.

如果 API 成功,则返回 napi_ok

¥Returns napi_ok if the API succeeded.

此函数向运行时指示由 JavaScript 对象(即指向由原生插件分配的自身内存的 JavaScript 对象)保持活动的外部分配内存量。注册外部分配的内存可能会(但不保证)比其他方式更频繁地触发全局垃圾收集。

¥This function gives the runtime an indication of the amount of externally allocated memory that is kept alive by JavaScript objects (i.e. a JavaScript object that points to its own memory allocated by a native addon). Registering externally allocated memory may, but is not guaranteed to, trigger global garbage collections more often than it would otherwise.

此函数应以插件减少的外部内存不超过增加的外部内存的方式调用。

¥This function is expected to be called in a manner such that an addon does not decrease the external memory more than it has increased the external memory.