UnionPointer<T extends Union>
LogoDart

UnionPointer<T extends Union>#

extension UnionPointer<T extends Union> on Pointer<T>

Annotations: @Since.new('2.14')

Extension on Pointer specialized for the type argument Union.

Properties#

ref extension read / write#

T get ref

A Dart view of the union referenced by this pointer.

Reading ref creates a reference accessing the fields of this union backed by native memory at address. The address must be aligned according to the union alignment rules of the platform.

Assigning to ref copies contents of the union into the native memory starting at address.

This extension method must be invoked on a receiver of type Pointer<T> where T is a compile-time constant type.

Available on Pointer<T extends NativeType>, provided by the UnionPointer<T extends Union> extension

Implementation
external T get ref;

external set ref(T value);

Methods#

deprecated elementAt() extension#

Pointer<T> elementAt(int index)

DEPRECATED

Use operator + instead

Pointer arithmetic (takes element size into account).

Available on Pointer<T extends NativeType>, provided by the UnionPointer<T extends Union> extension

Implementation
@Deprecated('Use operator + instead')
external Pointer<T> elementAt(int index);

refWithFinalizer() extension#

T refWithFinalizer( Pointer<NativeFinalizerFunction<Void Function(Pointer<Void> token)>> finalizer, { Pointer<Void>? token, });

A Dart view of the union referenced by this pointer.

Creates a reference accessing the fields of this union backed by native memory at address. The address must be aligned according to the union alignment rules of the platform.

Attaches finalizer to the backing store of the union. If provided, token will be passed to finalizer, otherwise the pointer (this) itself will be passed. The pointer (this) must not be used anymore if the union is not guaranteed to be kept alive. Prefer doing any native calls with the pointer before calling refWithFinalizer.

This extension method must be invoked on a receiver of type Pointer<T> where T is a compile-time constant type.

Available on Pointer<T extends NativeType>, provided by the UnionPointer<T extends Union> extension

Implementation
@Since('3.7')
external T refWithFinalizer(
  Pointer<NativeFinalizerFunction> finalizer, {
  Pointer<Void>? token,
});

Operators#

operator +() extension#

Pointer<T> operator +(int offset)

A pointer to the offsetth T after this one.

Returns a pointer to the T whose address is offset times the size of T after the address of this pointer. That is (this + offset).address == this.address + offset * sizeOf<T>().

Also (this + offset).value is equivalent to this[offset], and similarly for setting.

Available on Pointer<T extends NativeType>, provided by the UnionPointer<T extends Union> extension

Implementation
external Pointer<T> operator +(int offset);

operator -() extension#

Pointer<T> operator -(int offset)

A pointer to the offsetth T before this one.

Equivalent to this + (-offset).

Returns a pointer to the T whose address is offset times the size of T before the address of this pointer. That is, (this - offset).address == this.address - offset * sizeOf<T>().

Also, (this - offset).value is equivalent to this[-offset], and similarly for setting,

Available on Pointer<T extends NativeType>, provided by the UnionPointer<T extends Union> extension

Implementation
external Pointer<T> operator -(int offset);

operator []() extension#

T operator [](int index)

Creates a reference to access the fields of this union backed by native memory at address + sizeOf<T>() * index.

The address must be aligned according to the union alignment rules of the platform.

This extension method must be invoked on a receiver of type Pointer<T> where T is a compile-time constant type.

Available on Pointer<T extends NativeType>, provided by the UnionPointer<T extends Union> extension

Implementation
external T operator [](int index);

operator []=() extension#

void operator []=(int index, T value)

Copies the value union into native memory, starting at address * sizeOf<T>() * index.

This extension method must be invoked on a receiver of type Pointer<T> where T is a compile-time constant type.

Available on Pointer<T extends NativeType>, provided by the UnionPointer<T extends Union> extension

Implementation
external void operator []=(int index, T value);