# Trait core::alloc::GlobalAlloc[−][src]

    pub unsafe trait GlobalAlloc {
        unsafe fn alloc(&self, layout: Layout) -> *mut Opaque;
        unsafe fn dealloc(&self, ptr: *mut Opaque, layout: Layout);

        unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut Opaque { ... }
        unsafe fn realloc(
            &self,
            ptr: *mut Opaque,
            layout: Layout,
            new_size: usize
        ) -> *mut Opaque { ... }
    }

🔬 This is a nightly-only experimental API. (`allocator_api` #32838)

the precise API and guarantees it provides may be tweaked slightly, especially to possibly take into account the types being stored to make room for a future tracing garbage collector

A memory allocator that can be registered to be the one backing `std::alloc::Global` though the `#[global_allocator]` attributes.

## Required Methods

### `unsafe fn alloc(&self, layout: Layout) -> *mut Opaque`

🔬 This is a nightly-only experimental API. (`allocator_api` #32838)

the precise API and guarantees it provides may be tweaked slightly, especially to possibly take into account the types being stored to make room for a future tracing garbage collector

Allocate memory as described by the given `layout`.

Returns a pointer to newly-allocated memory, or NULL to indicate allocation failure.

# Safety

FIXME: what are the exact requirements?

### `unsafe fn dealloc(&self, ptr: *mut Opaque, layout: Layout)`

🔬 This is a nightly-only experimental API. (`allocator_api` #32838)

the precise API and guarantees it provides may be tweaked slightly, especially to possibly take into account the types being stored to make room for a future tracing garbage collector

Deallocate the block of memory at the given `ptr` pointer with the given `layout`.

# Safety

FIXME: what are the exact requirements? In particular around layout fit. (See docs for the `Alloc` trait.)

## Provided Methods

### `unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut Opaque`

🔬 This is a nightly-only experimental API. (`allocator_api` #32838)

the precise API and guarantees it provides may be tweaked slightly, especially to possibly take into account the types being stored to make room for a future tracing garbage collector

### `unsafe fn realloc(
&self,
ptr: *mut Opaque,
layout: Layout,
new_size: usize
) -> *mut Opaque`

🔬 This is a nightly-only experimental API. (`allocator_api` #32838)

the precise API and guarantees it provides may be tweaked slightly, especially to possibly take into account the types being stored to make room for a future tracing garbage collector

Shink or grow a block of memory to the given `new_size`. The block is described by the given `ptr` pointer and `layout`.

Return a new pointer (which may or may not be the same as `ptr`), or NULL to indicate reallocation failure.

If reallocation is successful, the old `ptr` pointer is considered to have been deallocated.

# Safety

`new_size`, when rounded up to the nearest multiple of `old_layout.align()`, must not overflow (i.e. the rounded value must be less than `usize::MAX`).

FIXME: what are the exact requirements? In particular around layout fit. (See docs for the `Alloc` trait.)

## Implementors

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g. `str,u8` or `String,struct:Vec,test`)