Class UnmanagedMemoryHandle
Represents managed wrapper of the unmanaged memory.
Namespace: DotNext.Runtime.InteropServices
Assembly: DotNext.Unsafe.dll
Syntax
public abstract class UnmanagedMemoryHandle : SafeHandle, ICloneable, IEquatable<UnmanagedMemoryHandle>, IUnmanagedMemory, IDisposable
Remarks
The allocated unmanaged memory is not controlled by GC. However, the unmanaged memory will be released automatically if GC collects the instance of this type.
Properties
| Improve this Doc View SourceBytes
Gets a span of bytes from the current instance.
Declaration
public Span<byte> Bytes { get; }
Property Value
| Type | Description |
|---|---|
| Span<Byte> |
IsInvalid
Indicates that this object is no longer valid.
Declaration
public override sealed bool IsInvalid { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
Pointer
Gets a pointer to the allocated unmanaged memory.
Declaration
public Pointer<byte> Pointer { get; }
Property Value
| Type | Description |
|---|---|
| Pointer<Byte> |
Size
Gets size of allocated unmanaged memory, in bytes.
Declaration
public abstract long Size { get; }
Property Value
| Type | Description |
|---|---|
| Int64 |
Methods
| Improve this Doc View SourceAsStream()
Represents unmanaged memory as stream.
Declaration
public Stream AsStream()
Returns
| Type | Description |
|---|---|
| Stream | The stream of unmanaged memory. |
BitwiseCompare(UnmanagedMemoryHandle)
Bitwise comparison of the memory blocks.
Declaration
public int BitwiseCompare(UnmanagedMemoryHandle other)
Parameters
| Type | Name | Description |
|---|---|---|
| UnmanagedMemoryHandle | other | The block of memory to be compared. |
Returns
| Type | Description |
|---|---|
| Int32 | Comparison result which has the semantics as return type of |
BitwiseEquals(UnmanagedMemoryHandle)
Computes bitwise equality between two blocks of memory.
Declaration
public bool BitwiseEquals(UnmanagedMemoryHandle other)
Parameters
| Type | Name | Description |
|---|---|---|
| UnmanagedMemoryHandle | other | The block of memory to be compared. |
Returns
| Type | Description |
|---|---|
| Boolean | true, if both memory blocks have the same bytes; otherwise, false. |
Clear()
Sets all bits of allocated memory to zero.
Declaration
public void Clear()
Equals(UnmanagedMemoryHandle)
Determines whether the given handle points to the same unmanaged memory as this handle.
Declaration
public bool Equals(UnmanagedMemoryHandle other)
Parameters
| Type | Name | Description |
|---|---|---|
| UnmanagedMemoryHandle | other | The handle to be compared. |
Returns
| Type | Description |
|---|---|
| Boolean | true, if the given handle points to the same unmanaged memory as this handle; otherwise, false. |
Equals(Object)
Determines whether the given handle points to the same unmanaged memory as this handle.
Declaration
public override bool Equals(object other)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | other | The handle to be compared. |
Returns
| Type | Description |
|---|---|
| Boolean | true, if the given handle points to the same unmanaged memory as this handle; otherwise, false. |
GetHashCode()
Returns hash code of the memory address.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| Int32 | The hash code of the memory address. |
ReadFrom(Pointer<Byte>)
Copies bytes from the source memory to the memory identified by this object.
Declaration
public void ReadFrom(Pointer<byte> source)
Parameters
| Type | Name | Description |
|---|---|---|
| Pointer<Byte> | source | The pointer to the source unmanaged memory. |
ReadFrom(Stream)
Copies bytes from the specified source stream into unmanaged memory.
Declaration
public long ReadFrom(Stream source)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | source | The readable stream. |
Returns
| Type | Description |
|---|---|
| Int64 | The actual number of copied elements. |
ReadFromAsync(Stream)
Copies bytes from the given stream to the memory location identified by this object asynchronously.
Declaration
public Task<long> ReadFromAsync(Stream source)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | source | The source stream. |
Returns
| Type | Description |
|---|---|
| Task<Int64> |
ReleaseHandle()
Releases unmanaged memory.
Declaration
protected override sealed bool ReleaseHandle()
Returns
| Type | Description |
|---|---|
| Boolean | true if unmanaged memory is released successfully; otherwise, false. |
ToByteArray()
Creates a copy of unmanaged memory inside of managed heap.
Declaration
public byte[] ToByteArray()
Returns
| Type | Description |
|---|---|
| Byte[] | A copy of unmanaged memory in the form of byte array. |
ToString()
Returns address of this memory in hexadecimal format.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| String | The address of this memory. |
WriteTo(Pointer<Byte>)
Copies elements from the current memory location to the specified memory location.
Declaration
public void WriteTo(Pointer<byte> destination)
Parameters
| Type | Name | Description |
|---|---|---|
| Pointer<Byte> | destination | The target memory location. |
WriteTo(UnmanagedMemoryHandle)
Copies bytes from the current memory location to the specified memory location.
Declaration
public long WriteTo(UnmanagedMemoryHandle destination)
Parameters
| Type | Name | Description |
|---|---|---|
| UnmanagedMemoryHandle | destination | The target memory location. |
Returns
| Type | Description |
|---|---|
| Int64 | The actual number of copied bytes. |
WriteTo(Stream)
Copies bytes from the memory location to the stream.
Declaration
public void WriteTo(Stream destination)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | destination | The destination stream. |
WriteToAsync(Stream)
Copies bytes from the memory location to the stream asynchronously.
Declaration
public Task WriteToAsync(Stream destination)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | destination | The destination stream. |
Returns
| Type | Description |
|---|---|
| Task | The task instance representing asynchronous state of the copying process. |
Operators
| Improve this Doc View SourceEquality(UnmanagedMemoryHandle, UnmanagedMemoryHandle)
Determines whether two handles point to the same unmanaged memory.
Declaration
public static bool operator ==(UnmanagedMemoryHandle first, UnmanagedMemoryHandle second)
Parameters
| Type | Name | Description |
|---|---|---|
| UnmanagedMemoryHandle | first | The first unmanaged memory handle. |
| UnmanagedMemoryHandle | second | The second unmanaged memory handle. |
Returns
| Type | Description |
|---|---|
| Boolean | true, if both handles point to the same unmanaged memory; otherwise, false. |
Inequality(UnmanagedMemoryHandle, UnmanagedMemoryHandle)
Determines whether two handles point to the the different blocks of unmanaged memory.
Declaration
public static bool operator !=(UnmanagedMemoryHandle first, UnmanagedMemoryHandle second)
Parameters
| Type | Name | Description |
|---|---|---|
| UnmanagedMemoryHandle | first | The first unmanaged memory handle. |
| UnmanagedMemoryHandle | second | The second unmanaged memory handle. |
Returns
| Type | Description |
|---|---|
| Boolean | true, if both handles point to the different blocks of unmanaged memory; otherwise, false. |