disposeStructWithOpUnslotted<D extends RaylibStruct<D> > method
void
disposeStructWithOpUnslotted<D extends RaylibStruct<D> >(
- D struct,
- void fn(
- StructPointer<
D> ptr
- StructPointer<
inherited
Disposes struct, invokes fn with its underlying pointer, and then
unslots the temporary allocation backing the pointer, if any.
The allocation is removed from the temporary allocator without freeing its underlying memory. This is intended for APIs where the external call takes responsibility for freeing the memory.
The allocation is unslotted after fn completes, including when fn
throws.
Implementation
void disposeStructWithOpUnslotted<D extends RaylibStruct<D>>(
D struct,
void Function(StructPointer<D> ptr) fn,
) {
final ptr = struct.getOpAndDispose();
try {
fn(ptr);
} finally {
if (ptr.allocationKey case final key?) {
$.structAlloc<D>()!.Unslot(key);
}
}
}