Struct alloc_madvise::Memory

source ·
pub struct Memory { /* private fields */ }
Expand description

Allocated memory.

Example

const FOUR_MEGABYTES: usize = 4 * 1024 * 1024;

// Allocate 2 MiB of aligned, zeroed-out, sequential read memory.
// The memory will be automatically freed when it leaves scope.
let mut memory = Memory::allocate(FOUR_MEGABYTES, true, true).unwrap();

// Get a reference to a mutable slice.
let data: &mut [f32] = memory.as_mut();
data[0] = 1.234;
data[1] = 5.678;

// Get a reference to an immutable slice.
let reference: &[f32] = memory.as_ref();
assert_eq!(reference[0], 1.234);
assert_eq!(reference[1], 5.678);
assert_eq!(reference[2], 0.0);
assert_eq!(reference.len(), memory.len() / std::mem::size_of::<f32>());

Implementations§

Allocates memory of the specified number of bytes.

The optimal alignment will be determined by the number of bytes provided. If the amount of bytes is a multiple of 2MB, Huge/Large Page support is enabled.

Arguments
  • num_bytes - The number of bytes to allocate.
  • sequential - Whether or not the memory access pattern is sequential mostly.
  • clear - Whether or not to zero out the allocated memory.

Frees memory of the specified number of bytes.

The memory instance is required to be created by allocate.

Returns the number of bytes allocated.

Returns whether this instance has zero bytes allocated.

Returns a pointer to the data buffer.

Returns

A valid pointer.

Returns a mutable pointer to the data buffer.

Returns

A valid pointer.

Trait Implementations§

Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.