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

Allocate a Vec<T> of all-zero values.

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.) However, because of its unsafe nature, it should only be used when necessary.

Arguments:

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

Returns the created vector.

§Unsafe

This function is unsafe. It will not call any constructor of T. The user must ensure that a value with all bits being zero is meaningful for type T.