bulk_allocator/
lib.rs

1// Copyright 2020-2023 Shin Yoshida
2//
3// "LGPL-3.0-or-later OR Apache-2.0"
4//
5// This is part of rust-bulk-allocator
6//
7//  rust-bulk-allocator is free software: you can redistribute it and/or modify
8//  it under the terms of the GNU Lesser General Public License as published by
9//  the Free Software Foundation, either version 3 of the License, or
10//  (at your option) any later version.
11//
12//  rust-bulk-allocator is distributed in the hope that it will be useful,
13//  but WITHOUT ANY WARRANTY; without even the implied warranty of
14//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15//  GNU Lesser General Public License for more details.
16//
17//  You should have received a copy of the GNU Lesser General Public License
18//  along with rust-bulk-allocator.  If not, see <http://www.gnu.org/licenses/>.
19//
20// Licensed under the Apache License, Version 2.0 (the "License");
21// you may not use this file except in compliance with the License.
22// You may obtain a copy of the License at
23//
24//     http://www.apache.org/licenses/LICENSE-2.0
25//
26// Unless required by applicable law or agreed to in writing, software
27// distributed under the License is distributed on an "AS IS" BASIS,
28// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29// See the License for the specific language governing permissions and
30// limitations under the License.
31
32#![deny(missing_docs)]
33
34//! `bulk-allocator` provides implementations of [`GlobalAlloc`] that manage a memory cache.
35//! The instance fetches memory chunks from the backend and frees them on the drop at once for
36//! the performance.
37//!
38//! Method `dealloc` does not instantly free the specified pointer; instead, it pools the pointer
39//! within the cache.
40//!
41//! Method `alloc` acquires a memory chunk from the backend and fill the cache if necessary, and
42//! returns a requested pointer from the cache.
43//!
44//! It is when the instance is dropped that the memory chunks are deallocated.
45//!
46//! [`GlobalAlloc`]: std::alloc::GlobalAlloc
47
48mod bulk_b;
49mod layout_bulk_b;
50mod rb_tree;
51
52pub use bulk_b::BulkAlloc;
53pub use layout_bulk_b::{LayoutBulkAlloc, UnsafeLayoutBulkAlloc};
54
55/// The default byte count of the bulk memory that this crate allocates from the backend
56/// if no cache is.
57/// Note that if too large layout is requested, it may exceed this value that this crate
58/// acquires via the backend.
59pub const MEMORY_CHUNK_SIZE: usize = 64 * 1024;