2 个版本
使用旧的 Rust 2015
0.1.1 | 2019 年 7 月 27 日 |
---|---|
0.1.0 | 2019 年 7 月 25 日 |
#567 in 内存管理
7KB
140 行
tralloc: Rust 的跟踪分配器
此项目允许您将所有分配记录到 stderr、stdout 或文件中。
要使用它,请注册全局分配器并激活它
#![feature(global_allocator)]
extern crate tralloc;
#[global_allocator]
static GLOBAL: tralloc::Allocator = tralloc::Allocator{};
fn main() {
tralloc::Allocator::write_to_stderr();
tralloc::Allocator::activate();
let s = String::from("Hello world!");
let mut v = Vec::new();
v.push(1);
以下内容将被打印
00029801ACDA259B A 00007FB780500000 000000000000000C
00029801ACDB7EFB A 00007FB780500010 0000000000000010
00029801ACDBAAC1 D 00007FB780500010 0000000000000010
00029801ACDBCD09 D 00007FB780500000 000000000000000C
列
- 时间(单调,因此不与任何时区相关联)
A
表示分配,D
表示释放- 内存地址
- 大小
您可以使用 activate
和 deactivate
方法在任何时候开始和停止收集。
注意
此存储库基于 tracing_allocator。由于 Rust 内部发生破坏性更改以及原作者缺乏沟通,因此进行了分叉。
依赖关系
~0.6–1MB
~15K SLoC