#chunk #slice #memory-pool

slice-pool2

A library for using a slice as a memory pool

2 releases

0.4.3 Jul 18, 2023
0.4.2 Jul 16, 2023

#2841 in Rust patterns

Download history 625/week @ 2024-07-08 429/week @ 2024-07-15 959/week @ 2024-07-22 802/week @ 2024-07-29 610/week @ 2024-08-05 1107/week @ 2024-08-12 397/week @ 2024-08-19 506/week @ 2024-08-26 330/week @ 2024-09-02 319/week @ 2024-09-09 449/week @ 2024-09-16 778/week @ 2024-09-23 523/week @ 2024-09-30 403/week @ 2024-10-07 826/week @ 2024-10-14 619/week @ 2024-10-21

2,411 downloads per month
Used in 10 crates (via retour)

MIT license

18KB
387 lines

slice-pool

A Rust library for using a slice as a memory pool.

Documentation

https://docs.rs/slice-pool2

Installation

Add this to your Cargo.toml:

[dependencies]
slice-pool2 = "0.4.2"

lib.rs:

This crate provides functionality for using a sliceable type as the underlying memory for a pool.

The allocated memory can be a mutable slice of any type.

use slice_pool::sync::SlicePool;

let values = vec![10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
let mut memory = SlicePool::new(values);
assert_eq!(memory.len(), 10);

// Not enough memory available (only 10 elements)
assert!(memory.alloc(11).is_none());

let mut first = memory.alloc(2).unwrap();
assert_eq!(*first, [10, 20]);
first[1] = 15;
assert_eq!(*first, [10, 15]);

let mem2 = memory.alloc(5).unwrap();
assert_eq!(*mem2, [30, 40, 50, 60, 70]);

No runtime deps