Class UnmanagedMemory<T>
Represents array-like unmanaged memory.
Inherited Members
Namespace: DotNext.Runtime.InteropServices
Assembly: DotNext.Unsafe.dll
Syntax
public sealed class UnmanagedMemory<T> : UnmanagedMemoryHandle, ICloneable, IEquatable<UnmanagedMemoryHandle>, IUnmanagedArray<T>, IUnmanagedMemory, IDisposable, IEnumerable<T> where T : struct
Type Parameters
Name | Description |
---|---|
T | The type of elements in the unmanaged memory. |
Remarks
All elements are allocated in unmanaged memory not controlled by Garbage Collector. However, the unmanaged memory will be released automatically if GC collects the instance of this type.
Constructors
| Improve this Doc View SourceUnmanagedMemory()
Allocates the block of unmanaged memory which is equal to size of type T
.
Declaration
public UnmanagedMemory()
UnmanagedMemory(Int32, Boolean)
Allocates the block of unmanaged memory.
Declaration
public UnmanagedMemory(int length, bool zeroMem = true)
Parameters
Type | Name | Description |
---|---|---|
Int32 | length | The number of elements in the unmanaged memory. |
Boolean | zeroMem | Sets all bytes of allocated memory to zero. |
Properties
| Improve this Doc View SourceLength
Gets the number of elements in the unmanaged memory.
Declaration
public int Length { get; }
Property Value
Type | Description |
---|---|
Int32 |
Pointer
Gets a pointer to the allocated unmanaged memory.
Declaration
public Pointer<T> Pointer { get; }
Property Value
Type | Description |
---|---|
Pointer<T> |
Size
Gets the size of allocated unmanaged memory, in bytes.
Declaration
public override long Size { get; }
Property Value
Type | Description |
---|---|
Int64 |
Overrides
| Improve this Doc View SourceSpan
Gets a span from the current instance.
Declaration
public Span<T> Span { get; }
Property Value
Type | Description |
---|---|
Span<T> |
Methods
| Improve this Doc View SourceBitwiseCompare(T[])
Bitwise comparison of the memory blocks.
Declaration
public int BitwiseCompare(T[] other)
Parameters
Type | Name | Description |
---|---|---|
T[] | other | The array to be compared. |
Returns
Type | Description |
---|---|
Int32 | Comparison result which has the semantics as return type of |
BitwiseCompare(Pointer<T>)
Bitwise comparison of the memory blocks.
Declaration
public int BitwiseCompare(Pointer<T> other)
Parameters
Type | Name | Description |
---|---|---|
Pointer<T> | other | The block of memory to be compared. |
Returns
Type | Description |
---|---|
Int32 | Comparison result which has the semantics as return type of |
BitwiseEquals(T[])
Computes bitwise equality between this array and the specified managed array.
Declaration
public bool BitwiseEquals(T[] other)
Parameters
Type | Name | Description |
---|---|---|
T[] | other | The array to be compared. |
Returns
Type | Description |
---|---|
Boolean | true, if both memory blocks have the same bytes; otherwise, false. |
BitwiseEquals(Pointer<T>)
Computes bitwise equality between two blocks of memory.
Declaration
public bool BitwiseEquals(Pointer<T> other)
Parameters
Type | Name | Description |
---|---|---|
Pointer<T> | other | The block of memory to be compared. |
Returns
Type | Description |
---|---|
Boolean | true, if both memory blocks have the same bytes; otherwise, false. |
Box(T)
Allocates a new unmanaged memory and place the given value into it.
Declaration
public static UnmanagedMemory<T> Box(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to be placed into unmanaged memory. |
Returns
Type | Description |
---|---|
UnmanagedMemory<T> | The object representing allocated unmanaged memory. |
Copy()
Creates bitwise copy of the unmanaged memory.
Declaration
public UnmanagedMemory<T> Copy()
Returns
Type | Description |
---|---|
UnmanagedMemory<T> | The independent copy of unmanaged memory. |
GetEnumerator()
Gets enumerator over all elements located in the unmanaged memory.
Declaration
public Pointer<T>.Enumerator GetEnumerator()
Returns
Type | Description |
---|---|
Pointer.Enumerator<> | The enumerator over all elements in the unmanaged memory. |
ReadFrom(T[])
Copies elements from the memory location to the managed array.
Declaration
public long ReadFrom(T[] source)
Parameters
Type | Name | Description |
---|---|---|
T[] | source | The source array. |
Returns
Type | Description |
---|---|
Int64 | The actual number of copied elements. |
ReadFrom(T[], Int64, Int64)
Copies elements from the specified array into the memory block identified by this object.
Declaration
public long ReadFrom(T[] source, long offset, long count)
Parameters
Type | Name | Description |
---|---|---|
T[] | source | The source array. |
Int64 | offset | The position in the source array from which copying begins. |
Int64 | count | The number of elements of type |
Returns
Type | Description |
---|---|
Int64 | Actual number of copied elements. |
ReadFrom(Pointer<T>)
Copies bytes from the source memory to the memory identified by this object.
Declaration
public void ReadFrom(Pointer<T> source)
Parameters
Type | Name | Description |
---|---|---|
Pointer<T> | source | The pointer to the source unmanaged memory. |
Reallocate(Int32)
Resizes a block of memory represented by this instance.
Declaration
public void Reallocate(int length)
Parameters
Type | Name | Description |
---|---|---|
Int32 | length | The new number of elements in the unmanaged array. |
ToArray()
Copies elements from the unmanaged array into managed heap.
Declaration
public T[] ToArray()
Returns
Type | Description |
---|---|
T[] | The array allocated in managed heap containing copied elements from unmanaged memory. |
WriteTo(T[])
Copies elements from the memory location to the managed array.
Declaration
public long WriteTo(T[] destination)
Parameters
Type | Name | Description |
---|---|---|
T[] | destination | The destination array. |
Returns
Type | Description |
---|---|
Int64 | The actual number of copied elements. |
WriteTo(T[], Int64, Int64)
Copies elements from the memory location to the managed array.
Declaration
public long WriteTo(T[] destination, long offset, long count)
Parameters
Type | Name | Description |
---|---|---|
T[] | destination | The destination array. |
Int64 | offset | The position in the destination array from which copying begins. |
Int64 | count | The number of array elements to be copied. |
Returns
Type | Description |
---|---|
Int64 | The actual number of copied elements. |
WriteTo(Pointer<T>)
Copies elements from the current memory location to the specified memory location.
Declaration
public void WriteTo(Pointer<T> destination)
Parameters
Type | Name | Description |
---|---|---|
Pointer<T> | destination | The target memory location. |
WriteTo(UnmanagedMemory<T>)
Copies elements from the current memory location to the specified memory location.
Declaration
public long WriteTo(UnmanagedMemory<T> destination)
Parameters
Type | Name | Description |
---|---|---|
UnmanagedMemory<T> | destination | The target memory location. |
Returns
Type | Description |
---|---|
Int64 | The actual number of copied elements. |
Operators
| Improve this Doc View SourceImplicit(UnmanagedMemory<T> to Pointer<T>)
Gets a pointer to the allocated unmanaged memory.
Declaration
public static implicit operator Pointer<T>(UnmanagedMemory<T> owner)
Parameters
Type | Name | Description |
---|---|---|
UnmanagedMemory<T> | owner | The owner of allocated unmanaged memory. |
Returns
Type | Description |
---|---|
Pointer<T> |
Implicit(UnmanagedMemory<T> to Span<T>)
Gets a span from the specified instance.
Declaration
public static implicit operator Span<T>(UnmanagedMemory<T> owner)
Parameters
Type | Name | Description |
---|---|---|
UnmanagedMemory<T> | owner | The owner of allocated unmanaged memory. |
Returns
Type | Description |
---|---|
Span<T> |