#memory-pool #memory #slice #pool #chunk #wrap

slice-pool

A library for using a slice as a memory pool

9 releases

Uses old Rust 2015

0.4.1 Jan 9, 2019
0.4.0 Jan 6, 2019
0.3.4 Jun 13, 2017
0.3.3 Dec 13, 2016
0.1.0 Dec 7, 2016

#696 in Memory management

Download history 388/week @ 2023-12-04 470/week @ 2023-12-11 545/week @ 2023-12-18 673/week @ 2023-12-25 312/week @ 2024-01-01 615/week @ 2024-01-08 1609/week @ 2024-01-15 619/week @ 2024-01-22 722/week @ 2024-01-29 650/week @ 2024-02-05 1115/week @ 2024-02-12 756/week @ 2024-02-19 824/week @ 2024-02-26 638/week @ 2024-03-04 536/week @ 2024-03-11 493/week @ 2024-03-18

2,542 downloads per month
Used in 10 crates (3 directly)

MIT license

17KB
381 lines

slice-pool

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

Documentation

https://docs.rs/slice-pool

Installation

Add this to your Cargo.toml:

[dependencies]
slice-pool = "0.4.1"

and this to your crate root:

extern crate slice_pool;

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