1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
//! # fastalloc
//!
//! A memory pooling library for Rust with type-safe handles and RAII-based memory management.
//!
//! **Version 1.5.0** - Production-ready release with performance optimizations and comprehensive documentation.
//!
//! ## Overview
//!
//! `fastalloc` provides memory pools that allow you to reuse allocations efficiently,
//! offering **1.3-1.4x faster allocation** than standard heap with the key benefits of:
//! - **Predictable latency**: No allocation spikes or fragmentation slowdowns
//! - **Cache locality**: Objects stored contiguously improve cache hit rates
//! - **Zero fragmentation**: Eliminates long-term heap fragmentation
//! - **Real-time guarantees**: Bounded worst-case allocation time
//!
//! Designed for use cases where objects are frequently created and destroyed:
//! - Game development (entities, particles, physics objects)
//! - Real-time systems (audio processing, robotics)
//! - High-performance servers (connection pooling, request handling)
//! - Embedded systems (constrained memory, no fragmentation)
//! - Scientific computing (matrices, particles, graph nodes)
//!
//! ## Features
//!
//! - **Multiple pool types**: Fixed-size, growing, thread-local, and thread-safe pools
//! - **Type-safe handles**: RAII-based handles that automatically return objects to the pool
//! - **Flexible configuration**: Builder pattern with extensive customization options
//! - **Multiple allocation strategies**: Stack (LIFO), free-list, and bitmap allocators
//! - **Optional statistics**: Track allocation patterns and pool usage (with `stats` feature)
//! - **no_std support**: Works in embedded and bare-metal environments
//!
//! ## Quick Start
//!
//! ```rust
//! use fastalloc::{FixedPool, PoolConfig};
//!
//! // Create a pool of 1000 integers
//! let pool = FixedPool::<i32>::new(1000).unwrap();
//!
//! // Allocate from the pool
//! let mut handle = pool.allocate(42).unwrap();
//!
//! // Use the value
//! assert_eq!(*handle, 42);
//! *handle = 100;
//! assert_eq!(*handle, 100);
//!
//! // Automatically returned to pool when handle is dropped
//! drop(handle);
//! ```
//!
//! ## Builder Configuration
//!
//! ```rust
//! use fastalloc::{PoolConfig, GrowthStrategy};
//!
//! let config: PoolConfig<i32> = PoolConfig::builder()
//! .capacity(1000)
//! .max_capacity(Some(10000))
//! .growth_strategy(GrowthStrategy::Exponential { factor: 2.0 })
//! .alignment(64) // Cache-line aligned
//! .pre_initialize(true)
//! .build()
//! .unwrap();
//! ```
//!
//! ## Performance
//!
//! Benchmark results (criterion.rs, release mode with LTO):
//! - Fixed pool allocation: ~3.5ns per object (1.3-1.4x faster than Box)
//! - Growing pool allocation: ~4.6ns per object
//! - Allocation reuse (LIFO): ~7.2ns per cycle
//!
//! See [BENCHMARKS.md](https://github.com/TIVerse/fastalloc/blob/master/BENCHMARKS.md)
//! for detailed methodology and results.
//!
//! ## Safety
//!
//! This crate minimizes the use of `unsafe` code and leverages Rust's ownership system
//! to prevent common memory safety issues:
//!
//! - ✅ **Use-after-free**: Handles maintain exclusive ownership via borrow checker
//! - ✅ **Double-free**: Allocator tracks which slots are in use (bitmap in debug mode)
//! - ✅ **Memory leaks**: RAII ensures objects are returned to pool when dropped
//! - ✅ **Data races**: Thread-safe types use proper synchronization (Arc + Mutex)
//!
//! Debug builds include additional runtime checks:
//! - Double-free detection (O(1) bitmap check)
//! - Index bounds validation
//! - Allocation state consistency
//!
//! See [SAFETY.md](https://github.com/TIVerse/fastalloc/blob/master/SAFETY.md)
//! for detailed safety guarantees and `unsafe` code documentation.
//!
//! ## Documentation
//!
//! - [API Documentation](https://docs.rs/fastalloc) - Complete API reference
//! - [BENCHMARKS.md](https://github.com/TIVerse/fastalloc/blob/master/BENCHMARKS.md) - Benchmark results, methodology, and library comparisons
//! - [SAFETY.md](https://github.com/TIVerse/fastalloc/blob/master/SAFETY.md) - Safety guarantees, unsafe code, and fragmentation behavior
//! - [ARCHITECTURE.md](https://github.com/TIVerse/fastalloc/blob/master/ARCHITECTURE.md) - Internal design and memory overhead analysis
//! - [ERROR_HANDLING.md](https://github.com/TIVerse/fastalloc/blob/master/ERROR_HANDLING.md) - Pool exhaustion strategies and error recovery
//! - [Examples](https://github.com/TIVerse/fastalloc/tree/master/examples) - Working code examples for common use cases
extern crate alloc;
extern crate std;
// Core modules
// Internal modules
// Optional modules
// Re-exports for convenience
pub use ;
pub use ;
pub use ;
pub use ;
pub use Poolable;
pub use ;
pub use LockFreePool;
pub use ;
// Prelude for convenient imports
// Provide Poolable implementations for common types
// Primitive integers
// Floating point
// Other primitives
// Common standard types
// Fixed-size arrays (common sizes)
// Tuples (up to 4 elements for common cases)