pub struct StdAllocator<T>(/* private fields */);Expand description
Implemented only for T = c_char
std::allocator<T>::allocate
std::allocator<T>::deallocate
Implementations§
Source§impl<T> StdAllocator<T>
impl<T> StdAllocator<T>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Create a new std::allocator<T> wrapper
Examples found in repository?
examples/alloc-tester.rs (line 90)
79fn main() {
80 println!("{: <25}{: <20}{: <20}", "", "thin::Alloc", "fat::Alloc", );
81 println!("{: <25}{: <20}{: <20}", "Allocator", "Alignment", "Alignment", );
82 println!("{:=<65}", "");
83 #[cfg(feature = "alloc")] Test::new("Global", || alloc::Global ) .fat().print();
84 #[cfg(c89)] Test::new("Malloc", || c::Malloc ).thin().fat().print();
85 #[cfg(c89)] Test::new("AlignedMalloc", || c::AlignedMalloc ) .fat().print();
86 #[cfg(cpp98)] Test::new("NewDelete", || cpp::NewDelete ).thin().fat().print();
87 #[cfg(cpp98)] Test::new("NewDeleteArray", || cpp::NewDeleteArray ).thin().fat().print();
88 #[cfg(cpp17)] Test::new("NewDeleteAligned", || cpp::NewDeleteAligned ) .fat().print();
89 #[cfg(cpp17)] Test::new("NewDeleteArrayAligned", || cpp::NewDeleteArrayAligned ) .fat().print();
90 #[cfg(cpp98)] Test::new("StdAllocator<char>", || cpp::StdAllocator::<char>::new() ) .fat().print();
91 #[cfg(all(windows, feature = "win32"))] {
92 println!();
93 println!("win32:");
94 Test::new("ProcessHeap", || win32::ProcessHeap ).thin().fat().print();
95 Test::new("Global", || win32::Global ).thin().fat().print();
96 Test::new("Local", || win32::Local ).thin().fat().print();
97 Test::new("CryptMem", || win32::CryptMem ).thin().fat().print();
98 Test::new("CoTaskMem", || win32::CoTaskMem ).thin().fat().print();
99 Test::new("VirtualCommit", || win32::VirtualCommit ).thin().fat().print();
100 }
101}Trait Implementations§
Source§impl Alloc for StdAllocator<c_char>
Safety Item Description
align✔️ Validated via fat::test::alignment
size✔️ Validated via fat::test::edge_case_sizes
pin✔️ StdAllocator<c_char> is 'static - allocations by std::allocator<T>::allocate live until std::allocator<T>::deallocated.
compatible✔️ StdAllocator<c_char> uses exclusively intercompatible std::allocator<char> functions
compatible✔️ std::allocator<char> is stateless (see is_always_equal checks in ffi.cpp)
exclusive✔️ std::allocator<T>::allocate allocations are exclusive/unique
exceptions✔️ std::allocator<T>::allocate can throw std::bad_alloc - the FFI wrapper around it catches std::bad_alloc and returns nullptr instead.
threads⚠️ thread-unsafe stdlibs existed once upon a time. I consider linking them in a multithreaded program defacto undefined behavior beyond the scope of this to guard against.
zeroed✔️ Validated via fat::test::zeroed_alloc
impl Alloc for StdAllocator<c_char>
| Safety Item | Description |
|---|---|
align | ✔️ Validated via fat::test::alignment |
size | ✔️ Validated via fat::test::edge_case_sizes |
pin | ✔️ StdAllocator<c_char> is 'static - allocations by std::allocator<T>::allocate live until std::allocator<T>::deallocated. |
compatible | ✔️ StdAllocator<c_char> uses exclusively intercompatible std::allocator<char> functions |
compatible | ✔️ std::allocator<char> is stateless (see is_always_equal checks in ffi.cpp) |
exclusive | ✔️ std::allocator<T>::allocate allocations are exclusive/unique |
exceptions | ✔️ std::allocator<T>::allocate can throw std::bad_alloc - the FFI wrapper around it catches std::bad_alloc and returns nullptr instead. |
threads | ⚠️ thread-unsafe stdlibs existed once upon a time. I consider linking them in a multithreaded program defacto undefined behavior beyond the scope of this to guard against. |
zeroed | ✔️ Validated via fat::test::zeroed_alloc |
Source§impl Alloc for StdAllocator<c_char>
impl Alloc for StdAllocator<c_char>
Source§fn alloc_uninit(
&self,
layout: Layout,
) -> Result<NonNull<MaybeUninit<u8>>, Self::Error>
fn alloc_uninit( &self, layout: Layout, ) -> Result<NonNull<MaybeUninit<u8>>, Self::Error>
Source§impl<T: Clone> Clone for StdAllocator<T>
impl<T: Clone> Clone for StdAllocator<T>
Source§fn clone(&self) -> StdAllocator<T>
fn clone(&self) -> StdAllocator<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for StdAllocator<T>
impl<T: Debug> Debug for StdAllocator<T>
Source§impl<T: Default> Default for StdAllocator<T>
impl<T: Default> Default for StdAllocator<T>
Source§fn default() -> StdAllocator<T>
fn default() -> StdAllocator<T>
Returns the “default value” for a type. Read more
Source§impl Free for StdAllocator<c_char>
Safety Item Description
compatible✔️ StdAllocator<c_char> uses exclusively intercompatible std::allocator<char> functions
compatible✔️ std::allocator<char> is stateless (see is_always_equal checks in ffi.cpp)
exceptions⚠️ std::allocator<T>::deallocate “Does not throw exceptions” (C++03 § 20.1.5 ¶ 2 Table 32), although it’s neither throw() nor noexcept.
threads⚠️ thread-unsafe stdlibs existed once upon a time. I consider linking them in a multithreaded program defacto undefined behavior beyond the scope of this to guard against.
impl Free for StdAllocator<c_char>
| Safety Item | Description |
|---|---|
compatible | ✔️ StdAllocator<c_char> uses exclusively intercompatible std::allocator<char> functions |
compatible | ✔️ std::allocator<char> is stateless (see is_always_equal checks in ffi.cpp) |
exceptions | ⚠️ std::allocator<T>::deallocate “Does not throw exceptions” (C++03 § 20.1.5 ¶ 2 Table 32), although it’s neither throw() nor noexcept. |
threads | ⚠️ thread-unsafe stdlibs existed once upon a time. I consider linking them in a multithreaded program defacto undefined behavior beyond the scope of this to guard against. |
Source§impl<T: Hash> Hash for StdAllocator<T>
impl<T: Hash> Hash for StdAllocator<T>
Source§impl<T> Meta for StdAllocator<T>
impl<T> Meta for StdAllocator<T>
Source§const MAX_ALIGN: Alignment
const MAX_ALIGN: Alignment
Indicates the maximum alignment this allocator should be expected to succeed in allocating.
Requesting an allocation with more alignment than this is almost certainly a bug. Read more
Source§const MAX_SIZE: usize = 18_446_744_073_709_551_615usize
const MAX_SIZE: usize = 18_446_744_073_709_551_615usize
Indicates the maximum size this allocator should be expected to succeed in allocating.
Requesting an allocation larger than this is almost certainly a bug. Read more
Source§const ZST_SUPPORTED: bool = false
const ZST_SUPPORTED: bool = false
Indicates if this allocator supports zero-sized allocations.
While this is nice and Rust-friendly, it may not be supported by C or C++ allocators.
Source§impl<T: Ord> Ord for StdAllocator<T>
impl<T: Ord> Ord for StdAllocator<T>
Source§fn cmp(&self, other: &StdAllocator<T>) -> Ordering
fn cmp(&self, other: &StdAllocator<T>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialEq> PartialEq for StdAllocator<T>
impl<T: PartialEq> PartialEq for StdAllocator<T>
Source§impl<T: PartialOrd> PartialOrd for StdAllocator<T>
impl<T: PartialOrd> PartialOrd for StdAllocator<T>
Source§impl Realloc for StdAllocator<c_char>
impl Realloc for StdAllocator<c_char>
Source§unsafe fn realloc_uninit(
&self,
ptr: NonNull<MaybeUninit<u8>>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<MaybeUninit<u8>>, Self::Error>
unsafe fn realloc_uninit( &self, ptr: NonNull<MaybeUninit<u8>>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<MaybeUninit<u8>>, Self::Error>
Source§unsafe fn realloc_zeroed(
&self,
ptr: NonNull<MaybeUninit<u8>>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<MaybeUninit<u8>>, Self::Error>
unsafe fn realloc_zeroed( &self, ptr: NonNull<MaybeUninit<u8>>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<MaybeUninit<u8>>, Self::Error>
impl<T: Copy> Copy for StdAllocator<T>
impl<T: Eq> Eq for StdAllocator<T>
impl Stateless for StdAllocator<c_char>
SAFETY: ✔️ std::allocator<char> is stateless (see is_always_equal checks in ffi.cpp)
impl<T> StructuralPartialEq for StdAllocator<T>
Auto Trait Implementations§
impl<T> Freeze for StdAllocator<T>
impl<T> RefUnwindSafe for StdAllocator<T>
impl<T> Send for StdAllocator<T>
impl<T> Sync for StdAllocator<T>
impl<T> Unpin for StdAllocator<T>
impl<T> UnwindSafe for StdAllocator<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more