pub struct Global;
🔬This is a nightly-only experimental API. (
allocator_api
#32838)Expand description
全局内存分配器。
此类型通过将调用转发到用 #[global_allocator]
属性注册的分配器 (如果有的话) 或 std
crate 的默认值来实现 Allocator
trait。
Note: 尽管此类型不稳定,但是可以通过 alloc
中的 free 函数 访问其提供的功能。
Trait Implementations§
source§impl Allocator for Global
impl Allocator for Global
source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api
#32838)尝试分配一块内存。 Read more
source§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api
#32838)行为类似于
allocate
,但也确保返回的内存被零初始化。 Read moresource§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
🔬This is a nightly-only experimental API. (
allocator_api
#32838)释放
ptr
引用的内存。 Read moresource§unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout ) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api
#32838)尝试扩展内存块。 Read more
source§unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout ) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api
#32838)行为类似于
grow
,但也确保在返回新内容之前将其设置为零。 Read moreimpl Copy for Global
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U, Global>> for Box<T, Global>
Auto Trait Implementations§
impl RefUnwindSafe for Global
impl Send for Global
impl Sync for Global
impl Unpin for Global
impl UnwindSafe for Global
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
从拥有的值中借用。 Read more