Skip to main content

mmap_field_vec_unchecked

Function mmap_field_vec_unchecked 

Source
unsafe fn mmap_field_vec_unchecked<F: PrimeField>(
    bytes: &[u8],
    count: usize,
) -> Vec<F>
Expand description

Zero-copy: constructs a Vec<F> whose backing storage is the mmap region itself, via Vec::from_raw_parts(mmap_ptr, len, len).

This is infallible by design: it performs no validation and simply reinterprets the bytes. All length/alignment validation must be done up front (see validate_field_section) so that this constructor — and therefore the first live mmap-backed Vec — is only ever reached once the entire file is known to be well-formed. That ordering is what makes the reader panic-free: an Err returned after one of these Vecs existed would drop it, calling the global allocator on mmap memory (undefined behaviour, observed as a free(): invalid pointer abort).

§Safety

  • bytes.len() must equal count * FIELD_ELEMENT_BYTES (caller guarantees this via validate_field_section).
  • The returned Vec<F> must never be dropped normally and must never grow: both would call dealloc/realloc on the mmap pointer. Callers keep it inside a core::mem::ManuallyDrop container (see MmapProverIndex) so Vec::drop never runs.
  • bytes must be aligned for F (8-byte alignment suffices for BigInt<4>; the format’s 32-byte section alignment covers this) and the underlying mmap must outlive the returned Vec<F>.