An open API service indexing awesome lists of open source software.

https://github.com/xigh/buffer-rs

Simple thread-safe, rust memory allocator from static buffer
https://github.com/xigh/buffer-rs

allocator memory rust thread-safe

Last synced: 3 months ago
JSON representation

Simple thread-safe, rust memory allocator from static buffer

Awesome Lists containing this project

README

        

### Simple, thread safe, buffer allocator in Rust

```rust
fn main() {
let mut bytes: [u8; 25] = [0; 25];
for n in 0..bytes.len() {
bytes[n] = (n % 255) as u8;
}

let memory = Buffer::init_from_bytes(&mut bytes);
println!("buffer size: {}", memory.len());

let bytes1 = memory.alloc(12);
if let Some(bytes1) = bytes1 {
println!("bytes1 at-1: {}", bytes1[1]);
}

let bytes2 = memory.alloc_mut(10);
if let Some(bytes2) = bytes2 {
println!("bytes2 at-0: {}", bytes2[0]);
bytes2[0] = 255;
println!("bytes2 at-0 [after=255]: {}", bytes2[0]);
}

let bytes3 = memory.alloc(20);
assert_eq!(None, bytes3);
}
```

![screenshot](screenshot.png)