Refactor core APIs, fix bugs, and improve safety
- Make image result/info structs readonly; improve error handling and memory safety in image library - Introduce IJobScheduler interface; move job scheduling docs to interface - Remove "index 0 invalid" convention from slot/sparse maps; fix Count logic - Add Owner<T> for disposable value types in low-level utilities - Improve ObjectPool<T> thread safety and logic - Change List<T>.RemoveAndSwapBack to return bool - Remove unsafe methods from generated math types; add debug range checks - Update benchmarks and enable collection checks in tests - Improve documentation, comments, and error messages - Bump assembly versions across all projects
This commit is contained in:
@@ -67,7 +67,7 @@ public readonly unsafe struct SharedPtr<T> : IEquatable<SharedPtr<T>>
|
||||
/// Ensures that the pointer is not shared and can be safely transferred or detached.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// UniquePtr<T> is designed to encapsulate a raw pointer, enforcing unique ownership semantics similar to C++'s std::unique_ptr.
|
||||
/// <see cref="UniquePtr{T}"/> is designed to encapsulate a raw pointer, enforcing unique ownership semantics similar to C++'s std::unique_ptr.
|
||||
/// </remarks>
|
||||
/// <typeparam name="T">The unmanaged type of the value to which the pointer refers.</typeparam>
|
||||
[NonCopyable]
|
||||
@@ -174,3 +174,47 @@ public ref struct Ref<T>
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides a wrapper for a value type that implements <see cref="IDisposable"/>, ensuring proper disposal of the contained value.
|
||||
/// </summary>
|
||||
/// <remarks>The <see cref="Owner{T}"/> class manages the lifetime of the contained value by calling its
|
||||
/// <see cref="IDisposable.Dispose"/> method when the wrapper is disposed or finalized. After disposal, accessing the value
|
||||
/// will throw an <see cref="ObjectDisposedException"/>.</remarks>
|
||||
/// <typeparam name="T">The value type to wrap. Must be a struct that implements <see cref="IDisposable"/>.</typeparam>
|
||||
public class Owner<T> : IDisposable
|
||||
where T : struct, IDisposable
|
||||
{
|
||||
private T _value;
|
||||
|
||||
private bool _disposed;
|
||||
|
||||
public Owner(T value)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
|
||||
~Owner()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public ref T Get()
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
return ref _value;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_value.Dispose();
|
||||
|
||||
_disposed = true;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user