StdAllocator

Struct StdAllocator 

Source
pub struct StdAllocator<T>(/* private fields */);
Expand description

Implementations§

Source§

impl<T> StdAllocator<T>

Source

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 ItemDescription
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§

fn alloc_uninit( &self, size: usize, ) -> Result<NonNull<MaybeUninit<u8>>, Self::Error>

Allocate at least size bytes of uninitialized memory. Read more
Source§

fn alloc_zeroed(&self, size: usize) -> Result<NonNull<u8>, Self::Error>

Allocate at least size bytes of zeroed memory. Read more
Source§

impl Alloc for StdAllocator<c_char>

Source§

fn alloc_uninit( &self, layout: Layout, ) -> Result<NonNull<MaybeUninit<u8>>, Self::Error>

Allocate at least layout.size() bytes of uninitialized memory aligned to layout.align(). Read more
Source§

fn alloc_zeroed(&self, layout: Layout) -> Result<NonNull<u8>, Self::Error>

Allocate at least layout.size() bytes of zeroed memory aligned to layout.align(). Read more
Source§

impl<T: Clone> Clone for StdAllocator<T>

Source§

fn clone(&self) -> StdAllocator<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for StdAllocator<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default> Default for StdAllocator<T>

Source§

fn default() -> StdAllocator<T>

Returns the “default value” for a type. Read more
Source§

impl Free for StdAllocator<c_char>

Safety ItemDescription
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§

unsafe fn free(&self, ptr: NonNull<MaybeUninit<u8>>, layout: Layout)

Deallocate an allocation, ptr, belonging to self. Read more
Source§

impl<T: Hash> Hash for StdAllocator<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> Meta for StdAllocator<T>

Source§

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

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

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§

type Error = ()

The error type returned from failed (re)allocation.
Source§

impl<T: Ord> Ord for StdAllocator<T>

Source§

fn cmp(&self, other: &StdAllocator<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq> PartialEq for StdAllocator<T>

Source§

fn eq(&self, other: &StdAllocator<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd> PartialOrd for StdAllocator<T>

Source§

fn partial_cmp(&self, other: &StdAllocator<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

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>

Reallocate an existing allocation, ptr, belonging to self. Read more
Source§

unsafe fn realloc_zeroed( &self, ptr: NonNull<MaybeUninit<u8>>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<MaybeUninit<u8>>, Self::Error>

Reallocate an existing allocation, ptr, belonging to self. Read more
Source§

impl<T: Copy> Copy for StdAllocator<T>

Source§

impl<T: Eq> Eq for StdAllocator<T>

Source§

impl Stateless for StdAllocator<c_char>

SAFETY: ✔️ std::allocator<char> is stateless (see is_always_equal checks in ffi.cpp)

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.