mmtk::util::rust_util::zeroed_alloc

Function new_zeroed_vec

source
pub(crate) fn new_zeroed_vec<T: Zeroable>(size: usize) -> Vec<T>
Expand description

Allocate a Vec<T> of all-zero values. T must implement [bytemuck::Zeroable].

This intends to be a faster alternative to vec![T(0), size]. It will allocate pre-zeroed buffer, and not store zero values to its elements as part of initialization.

It is useful when creating large (hundreds of megabytes) Vecs when the execution time is critical (such as during start-up, where a 100ms delay is obvious to small applications.)

Arguments:

  • T: The element type.
  • size: The length and capacity of the created vector.

Returns the created vector.