Skip to main content

reifydb_allocator/
lib.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2026 ReifyDB
3
4#![cfg_attr(not(debug_assertions), deny(clippy::disallowed_methods))]
5#![cfg_attr(debug_assertions, warn(clippy::disallowed_methods))]
6#![cfg_attr(not(debug_assertions), deny(warnings))]
7#![allow(clippy::tabs_in_doc_comments)]
8
9#[cfg(all(feature = "alloc-jemalloc", not(target_env = "msvc")))]
10pub mod backend {
11	use reifydb_allocator_jemalloc::{ALLOCATOR as JEMALLOC_ALLOCATOR, verify as jemalloc_verify};
12
13	pub type Allocator = reifydb_allocator_jemalloc::Allocator;
14	pub const ALLOCATOR: Allocator = JEMALLOC_ALLOCATOR;
15
16	pub fn verify() {
17		jemalloc_verify();
18	}
19}
20
21#[cfg(all(feature = "alloc-jemalloc", target_env = "msvc"))]
22compile_error!(
23	"reifydb-allocator: jemalloc is not supported on MSVC. \
24	 Use the (Phase 2) `alloc-mimalloc` feature instead. \
25	 See reifydb/plan-alloc.md."
26);
27
28#[macro_export]
29#[cfg(feature = "alloc-jemalloc")]
30macro_rules! set_global_allocator {
31	() => {
32		#[global_allocator]
33		static REIFYDB_GLOBAL_ALLOCATOR: $crate::backend::Allocator = $crate::backend::ALLOCATOR;
34	};
35}
36
37#[macro_export]
38#[cfg(not(feature = "alloc-jemalloc"))]
39macro_rules! set_global_allocator {
40	() => {};
41}
42
43#[cfg(feature = "alloc-jemalloc")]
44pub fn verify() {
45	backend::verify();
46}
47
48#[cfg(not(feature = "alloc-jemalloc"))]
49pub fn verify() {}