PointerBuffer<T extends NativeType>.fromSize constructor Null safety

PointerBuffer<T extends NativeType>.fromSize(
  1. int elementSize,
  2. int length
)

Implementation

PointerBuffer.fromSize(int elementSize, int length) {
  _elementSizePointer = malloc.allocate(sizeOf<Int32>());
  _elementSizePointer.value = elementSize;

  _sizePointer = malloc.allocate(sizeOf<Int32>());
  _sizePointer.value = length;

  _dataPointer = malloc.allocate(sizeOf<Pointer<Void>>());
  _dataPointer.value = malloc.allocate(elementSize * length);

  if(_dataPointer.value.address == nullptr.address)
    throw Exception("RawSample.fromSize: Failed to allocate a ${elementSize * length} bytes");

  ptr = malloc.allocate(sizeOf<Int64>() * 3);
  Int64List ptrData = ptr.cast<Int64>().asTypedList(3);

  ptrData[0] = _elementSizePointer.address;
  ptrData[1] = _sizePointer.address;
  ptrData[2] = _dataPointer.address;
}