Skip to content

Commit

Permalink
Removed pool initialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
Frostie314159 committed Aug 17, 2024
1 parent 6030953 commit 380e3fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
6 changes: 3 additions & 3 deletions examples/initialised.rs → examples/uninit.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use atomic_pool::{pool, Box};
use std::mem;

pool!(TestPool: [u32; 3], [0u32; 3]);
pool!(TestPool: [u32; 3]);

fn main() {
let mut buffer = unsafe { Box::<TestPool>::new_uninit() }.unwrap();
println!("Allocated new buffer, with contents: {:#x}", *buffer);
println!("Allocated new buffer.");

*buffer = 0xf00dbabeu32;

Expand All @@ -17,7 +17,7 @@ fn main() {

let reallocated_buffer = unsafe { Box::<TestPool>::new_uninit() }.unwrap();
println!(
"Reallocated buffer, with contents: 0x{:#x}",
"Reallocated buffer, with contents: {:#x}",
*reallocated_buffer
);
}
21 changes: 3 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ impl<P: Pool> Box<P> {
}

/// Turn this box into a raw pointer.
///
/// Once you turn a box into a raw pointer, it becomes your responsibility to free it properly again.
///
/// Once you turn a box into a raw pointer, it becomes your responsibility to free it properly again.
/// This can be done, by creating a box from that raw pointer again, using [Self::from_raw].
pub fn into_raw(b: Self) -> NonNull<P::Item> {
let res = b.ptr;
Expand All @@ -115,7 +115,7 @@ impl<P: Pool> Box<P> {
}

/// Create a box from a raw pointer.
///
///
/// # Safety
/// You must ensure, that the pointer points to valid memory, which was allocated from the pool in the generic parameter.
/// If you fail to do so, this will trigger a panic, once this box is dropped.
Expand Down Expand Up @@ -269,21 +269,6 @@ macro_rules! pool {
}
}
};
($vis:vis $name:ident: [$ty:ty; $n:expr], $initial_value:expr) => {
$vis struct $name { _uninhabited: ::core::convert::Infallible }
impl $crate::Pool for $name {
type Item = $ty;
type Storage = $crate::PoolStorageImpl<$ty, {$n}, {($n+31)/32}>;
fn get() -> &'static Self::Storage {
static POOL: $crate::PoolStorageImpl<$ty, {$n}, {($n+31)/32}> = {
let mut pool_storage_impl = $crate::PoolStorageImpl::new();
pool_storage_impl.data = unsafe { ::core::mem::transmute($initial_value) };
pool_storage_impl
};
&POOL
}
}
};
}
#[cfg(test)]
mod test {
Expand Down

0 comments on commit 380e3fb

Please sign in to comment.