create static method

Pointer<DynamicAlignedArray> create({
  1. int initialCapacity = 16,
  2. int elementSize = 4,
  3. int alignment = 4,
})
override

Creates a DynamicAlignedArray instance with the specified parameters.

  • initialCapacity: The initial capacity of the array.
  • elementSize: The size of each element in the array.
  • alignment: The alignment requirement for the array. Returns a pointer to the allocated DynamicAlignedArray instance.

Implementation

static Pointer<DynamicAlignedArray> create({
  int initialCapacity = 16,
  int elementSize = 4,
  int alignment = 4,
}) {
  final ptr = calloc<DynamicAlignedArray>();
  ptr.ref
    ..length = 0
    ..capacity = initialCapacity
    ..elementSize = elementSize
    ..alignment = alignment;

  // Allocate aligned memory for data
  ptr.ref.data = calloc
      .allocAligned<DynamicAlignedArray>(
        elementSize * initialCapacity,
        alignment,
      )
      .cast();

  return ptr;
}