21 releases

0.0.117 Apr 20, 2024
0.0.116 Apr 20, 2024
0.0.108 Mar 30, 2024

#295 in Memory management

Download history 31/week @ 2024-06-02 23/week @ 2024-06-09 34/week @ 2024-06-16 20/week @ 2024-06-23 11/week @ 2024-06-30 8/week @ 2024-07-07 36/week @ 2024-07-14 32/week @ 2024-07-21 41/week @ 2024-07-28 20/week @ 2024-08-04 25/week @ 2024-08-11 11/week @ 2024-08-18 40/week @ 2024-08-25 25/week @ 2024-09-01 20/week @ 2024-09-08 17/week @ 2024-09-15

103 downloads per month
Used in 8 crates (2 directly)

MIT/Apache

1MB
19K SLoC

musli-allocator

github crates.io docs.rs build status

Allocation support for Müsli.

This crate contains two types of allocators:

  • The System allocator, which uses the system allocation facilities. Particularly std::alloc::System.
  • The Stack allocator, which can allocate buffers from a fixed-size slice.

Examples

use musli::{Allocator, Buf};

musli_allocator::with(|alloc| {
    let mut a = alloc.alloc().expect("allocation a failed");
    let mut b = alloc.alloc().expect("allocation b failed");

    b.write(b"He11o");
    a.write(b.as_slice());

    assert_eq!(a.as_slice(), b"He11o");
    assert_eq!(a.len(), 5);

    a.write(b" W0rld");

    assert_eq!(a.as_slice(), b"He11o W0rld");
    assert_eq!(a.len(), 11);

    let mut c = alloc.alloc().expect("allocation c failed");
    c.write(b"!");
    a.write(c.as_slice());

    assert_eq!(a.as_slice(), b"He11o W0rld!");
    assert_eq!(a.len(), 12);
});

Dependencies

~260–720KB
~17K SLoC