fix(napi): memory issues in create_external_buffer
This commit is contained in:
parent
d2b61ef01f
commit
0446e463c8
7 changed files with 76 additions and 10 deletions
16
bench/src/buffer.rs
Normal file
16
bench/src/buffer.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
use napi::{ContextlessResult, Env, JsBuffer, JsObject, Result};
|
||||
|
||||
#[contextless_function]
|
||||
pub fn bench_create_buffer(env: Env) -> ContextlessResult<JsBuffer> {
|
||||
let mut output = Vec::with_capacity(100000);
|
||||
output.push(1);
|
||||
output.push(2);
|
||||
env
|
||||
.create_buffer_with_data(output)
|
||||
.map(|v| Some(v.into_raw()))
|
||||
}
|
||||
|
||||
pub fn register_js(exports: &mut JsObject) -> Result<()> {
|
||||
exports.create_named_method("benchCreateBuffer", bench_create_buffer)?;
|
||||
Ok(())
|
||||
}
|
|
@ -3,7 +3,16 @@ extern crate napi_derive;
|
|||
|
||||
use napi::{JsObject, Result};
|
||||
|
||||
#[cfg(all(unix, not(target_env = "musl"), not(target_arch = "aarch64")))]
|
||||
#[global_allocator]
|
||||
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
|
||||
|
||||
#[cfg(windows)]
|
||||
#[global_allocator]
|
||||
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
||||
|
||||
mod async_compute;
|
||||
mod buffer;
|
||||
mod noop;
|
||||
mod plus;
|
||||
|
||||
|
@ -12,6 +21,7 @@ fn init(mut exports: JsObject) -> Result<()> {
|
|||
exports.create_named_method("noop", noop::noop)?;
|
||||
|
||||
async_compute::register_js(&mut exports)?;
|
||||
buffer::register_js(&mut exports)?;
|
||||
plus::register_js(&mut exports)?;
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue