Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce SharedRef<T> and UniqueRef<T> #207

Merged
merged 13 commits into from
Nov 4, 2021
Merged

Introduce SharedRef<T> and UniqueRef<T> #207

merged 13 commits into from
Nov 4, 2021

Conversation

Thealexbarney
Copy link
Owner

The SharedRef<T> struct allows reference counting objects. UniqueRef<T> ensures that an object always has a single owner and is disposed when it's not used anymore.

These types must never be copied and must always be disposed of properly. The NonCopyableDisposable attribute is used to mark these types.

A non-copyable-disposable (NCD) type has a few rules to ensure it's used properly:

  1. An NCD local variable must always be a using variable.
  2. An NCD should not be copied in any way, including copying structs that contain an NCD.
  3. An NCD field must not be assigned outside of a constructor. Methods like .Set() should be used instead.
  4. An NCD type must always be passed by reference.
  5. An NCD type may be returned from a function if the return statement directly returns a new NCD instance or if it's invoking another function that returns an NCD.
  6. Structs and classes containing an NCD should be disposed of properly, and should dispose of their NCD fields.
  7. A reference to an NCD must not be copied to a value.
  8. References to an NCD may be returned and assigned to variables freely.

@Thealexbarney Thealexbarney merged commit 0a8fb8a into master Nov 4, 2021
@Thealexbarney Thealexbarney deleted the il-stuff branch November 27, 2021 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant