Struct OwnedMem<T>
- Namespace
- MarymoorStudios.Core
- Assembly
- MarymoorStudios.Core.dll
A capability for the exclusive ownership rights to an underlying memory.
public struct OwnedMem<T> : IDisposable where T : unmanaged
Type Parameters
T
The element type.
- Implements
- Inherited Members
Remarks
This is a linear type. These rights can be destroyed (i.e. disposed) or transferred to another party, but they can't be copied or duplicated.
Constructors
OwnedMem(MemoryManager<T>)
Construct a new ownership capability from an existing (potentially pool-backed) memory object.
public OwnedMem(MemoryManager<T> memory)
Parameters
memory
MemoryManager<T>The memory whose ownership is irrevocably transferred to this new OwnedMem<T>.
OwnedMem(Memory<T>)
Construct a new ownership capability from an existing (potentially pool-backed) memory object.
public OwnedMem(Memory<T> memory)
Parameters
memory
Memory<T>The memory whose ownership is irrevocably transferred to this new OwnedMem<T>.
Properties
IsEmpty
Returns true if Length is 0.
public readonly bool IsEmpty { get; }
Property Value
Length
The number of items in the memory.
public readonly int Length { get; }
Property Value
Memory
Returns a borrowed reference to the underlying memory.
public readonly Memory<T> Memory { get; }
Property Value
- Memory<T>
Span
Returns a borrowed reference to the underlying memory's span.
public readonly Span<T> Span { get; }
Property Value
- Span<T>
Methods
Dispose()
Dispose pattern.
public void Dispose()
Slice(int)
Forms a slice out of the given memory, beginning at 'start'.
public OwnedMem<T> Slice(int start)
Parameters
start
intThe index at which to begin this slice.
Returns
- OwnedMem<T>
Remarks
REQUIRES: the specified start
index is in range (<0 or >Length).
Slice(int, int)
Forms a slice out of the given memory, beginning at 'start', of given length
public OwnedMem<T> Slice(int start, int length)
Parameters
start
intThe index at which to begin this slice.
length
intThe desired length for the slice (exclusive).
Returns
- OwnedMem<T>
Remarks
REQUIRES: specified start
or end index is in range (<0 or >Length).
Operators
implicit operator Memory<T>(OwnedMem<T>)
Returns a borrowed reference to the underlying memory.
public static implicit operator Memory<T>(OwnedMem<T> owned)
Parameters
owned
OwnedMem<T>
Returns
- Memory<T>
implicit operator ReadOnlyMemory<T>(OwnedMem<T>)
Returns a borrowed reference to the underlying memory.
public static implicit operator ReadOnlyMemory<T>(OwnedMem<T> owned)
Parameters
owned
OwnedMem<T>