Lines Matching refs:alloc
13831 use std::alloc::{Allocator, Global, Layout, System};
13912 #[doc(alias = "alloc")]
14015 pub use core::alloc::*;
14024 // the default implementations in libstd (`__rdl_alloc` etc. in `library/std/src/alloc.rs`)
14046 /// accessed through the [free functions in `alloc`](self#functions).
14053 pub use std::alloc::Global;
14057 /// This function forwards calls to the [`GlobalAlloc::alloc`] method
14061 /// This function is expected to be deprecated in favor of the `alloc` method
14066 /// See [`GlobalAlloc::alloc`].
14071 /// use std::alloc::{alloc, dealloc, Layout};
14075 /// let ptr = alloc(layout);
14085 pub unsafe fn alloc(layout: Layout) -> *mut u8 {
14141 /// use std::alloc::{alloc_zeroed, dealloc, Layout};
14166 let raw_ptr = if zeroed { alloc_zeroed(layout) } else { alloc(layout) };
14329 pub(crate) unsafe fn box_free<T: ?Sized, A: Allocator>(ptr: Unique<T>, alloc: A) {
14334 alloc.deallocate(ptr.cast().into(), layout)
14341 // This is the magic symbol to call the global alloc error handler. rustc generates
14358 /// [`set_alloc_error_hook`]: ../../std/alloc/fn.set_alloc_error_hook.html
14359 /// [`take_alloc_error_hook`]: ../../std/alloc/fn.take_alloc_error_hook.html
14370 // For alloc test `std::alloc::handle_alloc_error` can be used directly.
14372 pub use std::alloc::handle_alloc_error;
14379 use crate::alloc::Layout;
14426 use core::alloc::LayoutError;
14434 use crate::alloc::{handle_alloc_error, Allocator, Global, Layout};
14474 alloc: A,
14549 pub const fn new_in(alloc: A) -> Self {
14551 Self { ptr: Unique::dangling(), cap: 0, alloc }
14557 pub fn with_capacity_in(capacity: usize, alloc: A) -> Self {
14558 Self::allocate_in(capacity, AllocInit::Uninitialized, alloc)
14564 pub fn with_capacity_zeroed_in(capacity: usize, alloc: A) -> Self {
14565 Self::allocate_in(capacity, AllocInit::Zeroed, alloc)
14571 let (slice, alloc) = Box::into_raw_with_allocator(slice);
14572 RawVec::from_raw_parts_in(slice.as_mut_ptr(), slice.len(), alloc)
14598 Box::from_raw_in(slice, ptr::read(&me.alloc))
14602 fn allocate_in(capacity: usize, init: AllocInit, alloc: A) -> Self {
14604 Self::new_in(alloc)
14617 AllocInit::Uninitialized => alloc.allocate(layout),
14618 AllocInit::Zeroed => alloc.allocate_zeroed(layout),
14628 alloc,
14637 /// The `ptr` must be allocated (via the given allocator `alloc`), and with the given
14641 /// If the `ptr` and `capacity` come from a `RawVec` created via `alloc`, then this is
14644 pub unsafe fn from_raw_parts_in(ptr: *mut T, capacity: usize, alloc: A) -> Self {
14645 Self { ptr: unsafe { Unique::new_unchecked(ptr) }, cap: capacity, alloc }
14666 &self.alloc
14708 /// # extern crate alloc;
14710 /// # use alloc::raw_vec::RawVec;
14853 let ptr = finish_grow(new_layout, self.current_memory(), &mut self.alloc)?;
14872 let ptr = finish_grow(new_layout, self.current_memory(), &mut self.alloc)?;
14885 self.alloc.shrink(ptr, layout, new_layout).map_err(|_| TryReserveError::AllocError {
14903 alloc: &mut A,
14918 alloc.grow(ptr, old_layout, new_layout)
14921 alloc.allocate(new_layout)
14931 unsafe { self.alloc.deallocate(ptr, layout) }
15919 // But we still need to be able to get the alloc layout to drop.
16578 #[doc(alias = "alloc")]
19349 //! The [`alloc`](alloc/index.html) module defines the low-level interface to the
19359 #![stable(feature = "alloc", since = "1.36.0")]
19461 pub mod alloc;
19761 use crate::alloc::{
19983 /// # Ok::<(), std::alloc::AllocError>(())
20017 /// # Ok::<(), std::alloc::AllocError>(())
20048 /// # Ok::<(), std::alloc::AllocError>(())
20756 let (box_unique, alloc) = Box::into_unique(v);
20770 box_free(box_unique, alloc);
22061 use crate::alloc::{Allocator, Global};
22116 use core::alloc::Allocator;
22127 let (b, alloc) = Box::into_raw_with_allocator(b);
22128 Vec::from_raw_parts_in(b as *mut T, len, len, alloc)
22133 pub fn to_vec<T: ConvertVec, A: Allocator>(s: &[T], alloc: A) -> Vec<T, A> {
22134 T::to_vec(s, alloc)
22138 fn to_vec<A: Allocator>(s: &[Self], alloc: A) -> Vec<Self, A>
22145 default fn to_vec<A: Allocator>(s: &[Self], alloc: A) -> Vec<Self, A> {
22160 let mut vec = Vec::with_capacity_in(s.len(), alloc);
22181 fn to_vec<A: Allocator>(s: &[Self], alloc: A) -> Vec<Self, A> {
22182 let mut v = Vec::with_capacity_in(s.len(), alloc);
22434 /// use std::alloc::System;
22442 pub fn to_vec_in<A: Allocator>(&self, alloc: A) -> Vec<T, A>
22447 hack::to_vec(self, alloc)
23295 use crate::alloc::{
23762 /// # Ok::<(), std::alloc::AllocError>(())
23798 /// # Ok::<(), std::alloc::AllocError>(())
23829 /// # Ok::<(), std::alloc::AllocError>(())
24406 let (box_unique, alloc) = Box::into_unique(v);
24420 box_free(box_unique, alloc);
26716 // But we still need to be able to get the alloc layout to drop.
37960 use crate::alloc::{Allocator, Global, Layout};
39945 use crate::alloc::{Layout, LayoutError};
45847 use crate::alloc::{Allocator, Global};
45876 pub(super) alloc: A,
45927 &self.alloc
46077 self.as_slice().to_vec_in(self.alloc.clone()).into_iter()
46081 crate::slice::to_vec(self.as_slice(), self.alloc.clone()).into_iter()
46093 // `IntoIter::alloc` is not used anymore after this
46094 let alloc = ptr::read(&self.0.alloc);
46096 let _ = RawVec::from_raw_parts_in(self.0.buf.as_ptr(), self.0.cap, alloc);
46137 use crate::alloc::Allocator;
46179 // NB can't overflow since we would have had to alloc the address space
46222 use crate::alloc::Allocator;
46230 fn from_elem<A: Allocator>(elem: Self, n: usize, alloc: A) -> Vec<Self, A>;
46234 default fn from_elem<A: Allocator>(elem: Self, n: usize, alloc: A) -> Vec<Self, A> {
46235 let mut v = Vec::with_capacity_in(n, alloc);
46243 fn from_elem<A: Allocator>(elem: i8, n: usize, alloc: A) -> Vec<i8, A> {
46245 return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n };
46248 let mut v = Vec::with_capacity_in(n, alloc);
46258 fn from_elem<A: Allocator>(elem: u8, n: usize, alloc: A) -> Vec<u8, A> {
46260 return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n };
46263 let mut v = Vec::with_capacity_in(n, alloc);
46273 fn from_elem<A: Allocator>(elem: T, n: usize, alloc: A) -> Vec<T, A> {
46275 return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n };
46277 let mut v = Vec::with_capacity_in(n, alloc);
46282 use crate::alloc::{Allocator, Global};
46661 crate::slice::to_vec(iterator.as_slice(), crate::alloc::Global)
46876 use crate::alloc::{Allocator, Global};
47284 /// [`dealloc`]: crate::alloc::GlobalAlloc::dealloc
47332 /// use std::alloc::System;
47339 pub const fn new_in(alloc: A) -> Self {
47340 Vec { buf: RawVec::new_in(alloc), len: 0 }
47365 /// use std::alloc::System;
47387 pub fn with_capacity_in(capacity: usize, alloc: A) -> Self {
47388 Vec { buf: RawVec::with_capacity_in(capacity, alloc), len: 0 }
47422 /// [`dealloc`]: crate::alloc::GlobalAlloc::dealloc
47429 /// use std::alloc::System;
47448 /// let alloc = v.allocator();
47457 /// let rebuilt = Vec::from_raw_parts_in(p, len, cap, alloc.clone());
47463 pub unsafe fn from_raw_parts_in(ptr: *mut T, length: usize, capacity: usize, alloc: A) -> Self {
47464 unsafe { Vec { buf: RawVec::from_raw_parts_in(ptr, capacity, alloc), len: length } }
47524 /// use std::alloc::System;
47531 /// let (ptr, len, cap, alloc) = v.into_raw_parts_with_alloc();
47538 /// Vec::from_raw_parts_in(ptr, len, cap, alloc)
47549 let alloc = unsafe { ptr::read(me.allocator()) };
47550 (ptr, len, capacity, alloc)
48341 struct FillGapOnDrop<'a, T, A: core::alloc::Allocator> {
48353 impl<'a, T, A: core::alloc::Allocator> Drop for FillGapOnDrop<'a, T, A> {
49063 pub fn from_elem_in<T: Clone, A: Allocator>(elem: T, n: usize, alloc: A) -> Vec<T, A> {
49064 <T as SpecFromElem>::from_elem(elem, n, alloc)
49146 let alloc = self.allocator().clone();
49147 <[T]>::to_vec_in(&**self, alloc)
49156 let alloc = self.allocator().clone();
49157 crate::slice::to_vec(&**self, alloc)
49238 let alloc = ptr::read(me.allocator());
49250 alloc,
49315 // NB can't overflow since we would have had to alloc the address space
49734 use crate::alloc::{Allocator, Global};
49912 use crate::alloc::Allocator;
49955 use crate::alloc::{Allocator, Global};
50112 //! The alloc Prelude
50115 //! items of the `alloc` crate by adding a glob import to the top of modules:
50120 //! extern crate alloc;
50121 //! use alloc::prelude::v1::*;
50127 //! The first version of the prelude of `alloc` crate.
50298 //! [`Global`]: crate::alloc::Global
50299 //! [`Layout`]: crate::alloc::Layout
50300 //! [`Layout::for_value(&*value)`]: crate::alloc::Layout::for_value
50323 use crate::alloc::{handle_alloc_error, AllocError, Allocator, Global, Layout, WriteCloneIntoRaw};
50351 #[doc(alias = "alloc")]
50426 /// # Ok::<(), std::alloc::AllocError>(())
50452 /// # Ok::<(), std::alloc::AllocError>(())
50476 /// # Ok::<(), std::alloc::AllocError>(())
50498 /// use std::alloc::System;
50504 pub fn new_in(x: T, alloc: A) -> Self {
50505 let mut boxed = Self::new_uninit_in(alloc);
50522 /// use std::alloc::System;
50525 /// # Ok::<(), std::alloc::AllocError>(())
50529 pub fn try_new_in(x: T, alloc: A) -> Result<Self, AllocError> {
50530 let mut boxed = Self::try_new_uninit_in(alloc)?;
50544 /// use std::alloc::System;
50559 pub fn new_uninit_in(alloc: A) -> Box<mem::MaybeUninit<T>, A> {
50563 match Box::try_new_uninit_in(alloc) {
50577 /// use std::alloc::System;
50589 /// # Ok::<(), std::alloc::AllocError>(())
50593 pub fn try_new_uninit_in(alloc: A) -> Result<Box<mem::MaybeUninit<T>, A>, AllocError> {
50595 let ptr = alloc.allocate(layout)?.cast();
50596 unsafe { Ok(Box::from_raw_in(ptr.as_ptr(), alloc)) }
50610 /// use std::alloc::System;
50621 pub fn new_zeroed_in(alloc: A) -> Box<mem::MaybeUninit<T>, A> {
50625 match Box::try_new_zeroed_in(alloc) {
50643 /// use std::alloc::System;
50649 /// # Ok::<(), std::alloc::AllocError>(())
50655 pub fn try_new_zeroed_in(alloc: A) -> Result<Box<mem::MaybeUninit<T>, A>, AllocError> {
50657 let ptr = alloc.allocate_zeroed(layout)?.cast();
50658 unsafe { Ok(Box::from_raw_in(ptr.as_ptr(), alloc)) }
50665 pub fn pin_in(x: T, alloc: A) -> Pin<Self>
50669 Self::new_in(x, alloc).into()
50677 let (raw, alloc) = Box::into_raw_with_allocator(boxed);
50678 unsafe { Box::from_raw_in(raw as *mut [T; 1], alloc) }
50757 /// use std::alloc::System;
50774 pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit<T>], A> {
50775 unsafe { RawVec::with_capacity_in(len, alloc).into_box(len) }
50789 /// use std::alloc::System;
50800 pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit<T>], A> {
50801 unsafe { RawVec::with_capacity_zeroed_in(len, alloc).into_box(len) }
50837 let (raw, alloc) = Box::into_raw_with_allocator(self);
50838 unsafe { Box::from_raw_in(raw as *mut T, alloc) }
50876 let (raw, alloc) = Box::into_raw_with_allocator(self);
50877 unsafe { Box::from_raw_in(raw as *mut [T], alloc) }
50909 /// use std::alloc::{alloc, Layout};
50912 /// let ptr = alloc(Layout::new::<i32>()) as *mut i32;
50953 /// use std::alloc::System;
50956 /// let (ptr, alloc) = Box::into_raw_with_allocator(x);
50957 /// let x = unsafe { Box::from_raw_in(ptr, alloc) };
50963 /// use std::alloc::{Allocator, Layout, System};
50973 /// # Ok::<(), std::alloc::AllocError>(())
50980 pub unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self {
50981 Box(unsafe { Unique::new_unchecked(raw) }, alloc)
51011 /// use std::alloc::{dealloc, Layout};
51051 /// use std::alloc::System;
51054 /// let (ptr, alloc) = Box::into_raw_with_allocator(x);
51055 /// let x = unsafe { Box::from_raw_in(ptr, alloc) };
51062 /// use std::alloc::{Allocator, Layout, System};
51066 /// let (ptr, alloc) = Box::into_raw_with_allocator(x);
51070 /// alloc.deallocate(non_null.cast(), Layout::new::<String>());
51078 let (leaked, alloc) = Box::into_unique(b);
51079 (leaked.as_ptr(), alloc)
51095 let alloc = unsafe { ptr::read(&b.1) };
51096 (Unique::from(Box::leak(b)), alloc)
51472 let (raw, alloc) = Box::into_raw_with_allocator(s);
51473 unsafe { Box::from_raw_in(raw as *mut [u8], alloc) }
51529 let (raw, alloc): (*mut dyn Any, _) = Box::into_raw_with_allocator(self);
51530 Ok(Box::from_raw_in(raw as *mut T, alloc))
51561 let (raw, alloc): (*mut (dyn Any + Send), _) = Box::into_raw_with_allocator(self);
51562 Ok(Box::from_raw_in(raw as *mut T, alloc))
51593 let (raw, alloc): (*mut (dyn Any + Send + Sync), _) =
51595 Ok(Box::from_raw_in(raw as *mut T, alloc))
51750 let alloc = Box::allocator(self).clone();
51751 self.to_vec_in(alloc).into_boxed_slice()
51871 use crate::alloc::AllocError;
51909 assert_eq!(v.alloc.fuel.get(), 450);
51911 assert_eq!(v.alloc.fuel.get(), 250);