Ownership
Morph provides a clear ownership model through its memory primitives.
Ownership Rules
- Every value has exactly one owner at a time
iscreates an alias (shared ownership)anothercreates a copy (new owner)movetransfers ownership (old owner invalidated)
Ownership Transfer with move
buffer is CreateLargeBuffer();
newOwner is move buffer; // buffer is invalidated
// buffer should not be used after this point
Shared Access with Alias
data is LoadData();
view is data; // view and data share the same memory
// Both are valid, both see the same data
Independent Copy
original is LoadData();
backup is another original; // completely independent
// Modifying backup does not affect original
Next Steps
- Modules — Importing code