Function regex_automata::util::wire::alloc_aligned_buffer

source ·
pub(crate) fn alloc_aligned_buffer<T>(size: usize) -> (Vec<u8>, usize)
Expand description

Allocate a byte buffer of the given size, along with some initial padding such that buf[padding..] has the same alignment as T, where the alignment of T must be at most 8. In particular, callers should treat the first N bytes (second return value) as padding bytes that must not be overwritten. In all cases, the following identity holds:

let (buf, padding) = alloc_aligned_buffer::<StateID>(SIZE);
assert_eq!(SIZE, buf[padding..].len());

In practice, padding is often zero.

The requirement for 8 as a maximum here is somewhat arbitrary. In practice, we never need anything bigger in this crate, and so this function does some sanity asserts under the assumption of a max alignment of 8.