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
- Host: GitHub
- URL: https://github.com/xigh/buffer-rs
- Owner: xigh
- License: mit
- Created: 2021-12-27T18:18:02.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-12-28T17:02:34.000Z (over 3 years ago)
- Last Synced: 2025-01-08T06:20:09.923Z (5 months ago)
- Topics: allocator, memory, rust, thread-safe
- Language: Rust
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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);
}
```