Struct MemoryPointer<T>
Structure, which stores the pointer to the fixed memory.
Namespace: OnixS.SimpleBinaryEncoding
Assembly: OnixS.SimpleBinaryEncoding.dll
Syntax
public readonly struct MemoryPointer<T> : IDisposable, IEquatable<MemoryPointer<T>> where T : IEquatable<T>
Type Parameters
Name | Description |
---|---|
T | Type of contained data. |
Constructors
MemoryPointer(Memory<T>)
Constructor.
Declaration
public MemoryPointer(Memory<T> memory)
Parameters
Type | Name | Description |
---|---|---|
Memory<T> | memory | Managed memory buffer, which will be pinned. |
MemoryPointer(Void*, Int32)
Constructor.
Declaration
public MemoryPointer(void *unmanagedPointer, int length)
Parameters
Type | Name | Description |
---|---|---|
System.Void* | unmanagedPointer | Unmanaged memory buffer. |
System.Int32 | length | Length of memory buffer. |
Properties
IsEmpty
True, if the underlying buffer is empty, false otherwise.
Declaration
public readonly bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Length
Length of the buffer.
Declaration
public readonly int Length { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Offset
Offset from root memory block.
Declaration
public readonly int Offset { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Span
Gets Span.
Declaration
public readonly Span<T> Span { get; }
Property Value
Type | Description |
---|---|
Span<T> |
Methods
CopyTo(Span<T>)
Copy the content of the buffer to the span.
Declaration
public readonly void CopyTo(Span<T> destination)
Parameters
Type | Name | Description |
---|---|---|
Span<T> | destination | The destination span. |
Dispose()
Unpin underlying buffer, if required.
Declaration
public readonly void Dispose()
Equals(MemoryPointer<T>)
Indicates whether the current object is equal to another object of the same type.
Declaration
public readonly bool Equals(MemoryPointer<T> other)
Parameters
Type | Name | Description |
---|---|---|
MemoryPointer<T> | other | An object to compare with this object. |
Returns
Type | Description |
---|---|
System.Boolean | true if the current object is equal to the other parameter; otherwise, false. |
Equals(Object)
Indicates whether the current object is equal to another object of the same type.
Declaration
public override readonly bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | An object to compare with this object. |
Returns
Type | Description |
---|---|
System.Boolean | true if the current object is equal to the other parameter; otherwise, false. |
GetHashCode()
Serves as the default hash function.
Declaration
public override readonly int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 | A hash code for the current object. |
Slice(Int32)
Slice memory buffer.
Declaration
public readonly MemoryPointer<T> Slice(int start)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | start | Start of the slice. |
Returns
Type | Description |
---|---|
MemoryPointer<T> | Pointer to the memory slice. |
Slice(Int32, Int32)
Slice memory buffer.
Declaration
public readonly MemoryPointer<T> Slice(int start, int length)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | start | Start of the slice. |
System.Int32 | length | Length of the slice. |
Returns
Type | Description |
---|---|
MemoryPointer<T> | Pointer to the memory slice. |
ToArray()
Copy buffer content to the new array.
Declaration
public readonly T[] ToArray()
Returns
Type | Description |
---|---|
T[] | The new array, which contains buffer content. |
ToMemoryPointer(T[])
Pin array and creates a pointer to it.
Declaration
public readonly MemoryPointer<T> ToMemoryPointer(T[] array)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | Array to pin. |
Returns
Type | Description |
---|---|
MemoryPointer<T> | Pointer to the pinned array. |
ToMemoryPointer(Memory<T>)
Pin memory and creates a pointer to it.
Declaration
public readonly MemoryPointer<T> ToMemoryPointer(Memory<T> memory)
Parameters
Type | Name | Description |
---|---|---|
Memory<T> | memory | Memory to pin. |
Returns
Type | Description |
---|---|
MemoryPointer<T> | Pointer to the pinned memory. |
ToString()
Returns the string representation of an object.
Declaration
public override readonly string ToString()
Returns
Type | Description |
---|---|
System.String | The string representation of an object. |
TryCopyTo(Span<T>)
Try to copy the content of the buffer to the span.
Declaration
public readonly bool TryCopyTo(Span<T> destination)
Parameters
Type | Name | Description |
---|---|---|
Span<T> | destination | Destination span. |
Returns
Type | Description |
---|---|
System.Boolean | True, if copying is successful, false otherwise. |
Operators
Equality(MemoryPointer<T>, MemoryPointer<T>)
Declaration
public static bool operator ==(MemoryPointer<T> left, MemoryPointer<T> right)
Parameters
Type | Name | Description |
---|---|---|
MemoryPointer<T> | left | |
MemoryPointer<T> | right |
Returns
Type | Description |
---|---|
System.Boolean |
Implicit(T[] to MemoryPointer<T>)
Declaration
public static implicit operator MemoryPointer<T>(T[] array)
Parameters
Type | Name | Description |
---|---|---|
T[] | array |
Returns
Type | Description |
---|---|
MemoryPointer<T> |
Implicit(Memory<T> to MemoryPointer<T>)
Declaration
public static implicit operator MemoryPointer<T>(Memory<T> memory)
Parameters
Type | Name | Description |
---|---|---|
Memory<T> | memory |
Returns
Type | Description |
---|---|
MemoryPointer<T> |
Inequality(MemoryPointer<T>, MemoryPointer<T>)
Declaration
public static bool operator !=(MemoryPointer<T> left, MemoryPointer<T> right)
Parameters
Type | Name | Description |
---|---|---|
MemoryPointer<T> | left | |
MemoryPointer<T> | right |
Returns
Type | Description |
---|---|
System.Boolean |