Skip to main content

flat_slice_memory_size

Function flat_slice_memory_size 

Source
fn flat_slice_memory_size(array: &dyn Array) -> Option<usize>
Expand description

Computes array.to_data().get_slice_memory_size() for flat arrays without building the ArrayData.

The formulas mirror Arrow’s ArrayData::get_slice_memory_size (arrow-data 59.2.0, get_slice_memory_size in arrow-data/src/data.rs):

  • a fixed-width value buffer costs len * byte_width, where the byte width is the one of the type’s buffer layout, as reported by DataType::primitive_width,
  • the value bitmap of a boolean array costs ceil(len / 8),
  • the offsets buffer of a variable-width array holds len + 1 boundaries and costs (len + 1) * offset_width,
  • the visible value bytes of a variable-width array cost offset[len] - offset[0],
  • the validity bitmap costs ceil(len / 8), but only if the slice contains a null: converting an array to ArrayData drops a validity bitmap without any null (ArrayDataBuilder::build), so Arrow only sees one when null_count is non-zero.

Returns None for data types that are left to Arrow’s general computation (nested, view, dictionary, union, FixedSizeBinary, Null, …) and when the size computation overflows usize, which Arrow reports as an error. Callers must then fall back to Arrow.