Skip to main content

Module typed_array

Module typed_array 

Source
Expand description

Typed contiguous array for v2 runtime.

TypedArray<T> is a 24-byte #[repr(C)] heap object with a HeapHeader, a pointer to a contiguous T buffer, length, and capacity. The compiler monomorphizes: Array<number> and Array<i32> are different TypedArray instantiations with no element-level type checking.

§Memory layout (24 bytes)

Offset  Size  Field
------  ----  -----
  0       8   header (HeapHeader — refcount at offset 0)
  8       8   data (*mut T — pointer to contiguous T buffer)
 16       4   len (element count)
 20       4   cap (allocated capacity)

Structs§

TypedArray
Typed contiguous array with refcounted header.

Constants§

ELEM_TYPE_BOOL
_pad-byte discriminant for TypedArray<u8> carrying bool elements.
ELEM_TYPE_CHAR
_pad-byte discriminant for TypedArray<char>.
ELEM_TYPE_DECIMAL
_pad-byte discriminant for TypedArray<*const DecimalObj>.
ELEM_TYPE_F32
_pad-byte discriminant for TypedArray<f32>.
ELEM_TYPE_F64
_pad-byte discriminant for TypedArray<f64>.
ELEM_TYPE_I8
_pad-byte discriminant for TypedArray<i8>.
ELEM_TYPE_I16
_pad-byte discriminant for TypedArray<i16>.
ELEM_TYPE_I32
_pad-byte discriminant for TypedArray<i32>.
ELEM_TYPE_I64
_pad-byte discriminant for TypedArray<i64>.
ELEM_TYPE_STRING
_pad-byte discriminant for TypedArray<*const StringObj>.
ELEM_TYPE_TYPED_OBJECT
_pad-byte discriminant for TypedArray<*const TypedObjectStorage>.
ELEM_TYPE_U8
_pad-byte discriminant for TypedArray<u8> carrying u8 elements.
ELEM_TYPE_U16
_pad-byte discriminant for TypedArray<u16>.
ELEM_TYPE_U32
_pad-byte discriminant for TypedArray<u32>.
ELEM_TYPE_UNKNOWN
_pad-byte discriminant for an unstamped / unknown element type.

Functions§

read_elem_type
Read the element-type discriminant stamped in the _pad byte (offset 7).
release_v2_typed_array
Release one refcount share of a v2-raw *mut TypedArray<T> carrier; on the last share, read the stamped element type and free the array via the matching monomorphized drop_array / drop_array_heap.
retain_v2_typed_array
Retain (bump the refcount of) a v2-raw *mut TypedArray<T> carrier.