Allocate method
Allocates or syncs value to a tracked slot at key.
Implementation
StructPointer<X> Allocate(X value, [String? key]) {
final op = value.op;
if (op != null) {
if (value.$state.isFirstSync) {
if (value.$state.isDisposed) return op;
if (!temp.doSync) return op;
// full sync once to push pre-promotion Dart state to memory
temp.debugSyncInfo('[SYNC] ${value.structName} first sync');
value.structWriteInto(op);
value.$state.isFirstSync = false;
} else {
// already live, setters handle write-through, skip full sync
temp.debugSyncInfo('[SYNC] ${value.structName} skipping sync (live)');
}
return op;
}
if (value.$state.isDisposed) {
throw StateError('You are trying to allocate disposed $value object!');
}
String baseKey = getBaseKey(value, _slotKey(key));
final p = struct.ptr(value._requiresOp ? AtUnique(key: baseKey) : At(baseKey));
temp.debugSyncInfo('[SYNC] ${value.structName} allocate into \'${p.allocationKey}\'');
value.structAllocateInto(temp, p, p.allocationKey ?? baseKey);
value.structWriteInto(p);
if (value._requiresOp) {
value.op = p;
value.$state.isFirstSync = false;
}
return p;
}