Crates.io | unkai |
lib.rs | unkai |
version | 0.2.0 |
source | src |
created_at | 2024-08-30 10:15:29.895584 |
updated_at | 2024-08-30 10:15:29.895584 |
description | Unkai is a tool set for Rust's memory allocation APIs mainly focus on tracking and conditional analyzing / limiting memory usage. |
homepage | |
repository | https://github.com/waynexia/unkai |
max_upload_size | |
id | 1357561 |
size | 39,937 |
Unkai is a tool set for Rust's memory allocation APIs mainly focus on tracking and conditional analyzing / limiting memory usage.
It's now compatible with two major forms of allocator API in the standard library:
GlobalAlloc
: the global memory allocator for all default memory allocation.Allocator
: the unstable allocator API (tracking issue) that allows
changing Allocator
for a specific struct like Box
or Vec
.GlobalAlloc
The entrypoint is [UnkaiGlobalAlloc
]. Only need to wrap your original global
allocator with [UnkaiGlobalAlloc
] like this:
use tikv_jemallocator::Jemalloc;
use unkai::UnkaiGlobalAlloc;
#[global_allocator]
static UNKAI: UnkaiGlobalAlloc<Jemalloc> = UnkaiGlobalAlloc::new(Jemalloc {}, 99, 5, 10, 0);
Allocator
Notice that Allocator
only available when the unstable feature allocator_api
is enabled via #![feature(allocator_api)]
. And enabling unstable feature requires
the nigntly channel Rust toolchain.
The entrypoint is [Unkai
]. Example usage:
let mut vec_container: Vec<usize, UnkaiGlobal> = Vec::with_capacity_in(10000, Unkai::default());
assert_eq!(vec_container.allocator().report_usage(), 80000);
There is also an example file examples/allocator.rs
that shows more usages.
TBD
GlobalAlloc
GlobalAlloc
Allocator
There are some example files under examples/
. They are:
allocator.rs
: shows the usage of Allocator
wrapper to track memory consumption at runtime.collections.rs
: shows the usage of GlobalAlloc
and stack trackingTo run example, use command like the following:
cargo run --example collections --release