Class UnmanagedMemory
Provides native memory allocation facilities.
Inherited Members
Namespace: DotNext.Buffers
Assembly: DotNext.Unsafe.dll
Syntax
public static class UnmanagedMemory
Methods
View SourceAllocatePageAlignedMemory(int, bool)
Allocates page-aligned memory.
Declaration
[CLSCompliant(false)]
public static IMemoryOwner<byte> AllocatePageAlignedMemory(int size, bool roundUpSize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| int | size | The number of bytes to be allocated. |
| bool | roundUpSize | true to round up the |
Returns
| Type | Description |
|---|---|
| IMemoryOwner<byte> | A memory owner that represents page-aligned memory block. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
AllocateSystemPages(int)
Allocates a specified number of system pages.
Declaration
public static IMemoryOwner<byte> AllocateSystemPages(int pageCount)
Parameters
| Type | Name | Description |
|---|---|---|
| int | pageCount | The number of system pages to be allocated. |
Returns
| Type | Description |
|---|---|
| IMemoryOwner<byte> | A memory owner that represents allocated system pages. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
AllocateZeroed<T>(int)
Allocates and zeroes a block of unmanaged memory of the specified size, in elements.
Declaration
[CLSCompliant(false)]
public static IUnmanagedMemory<T> AllocateZeroed<T>(int length) where T : unmanaged
Parameters
| Type | Name | Description |
|---|---|---|
| int | length | The number of elements to be allocated in unmanaged memory. |
Returns
| Type | Description |
|---|---|
| IUnmanagedMemory<T> | The object representing allocated unmanaged memory. |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
Allocate<T>(int)
Allocates a block of unmanaged memory of the specified size, in elements.
Declaration
[CLSCompliant(false)]
public static IUnmanagedMemory<T> Allocate<T>(int length) where T : unmanaged
Parameters
| Type | Name | Description |
|---|---|---|
| int | length | The number of elements to be allocated in unmanaged memory. |
Returns
| Type | Description |
|---|---|
| IUnmanagedMemory<T> | The object representing allocated unmanaged memory. |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
Discard<T>(Span<T>)
Returns the backing RAM back to the OS.
Declaration
public static void Discard<T>(Span<T> memoryBlock) where T : unmanaged
Parameters
| Type | Name | Description |
|---|---|---|
| Span<T> | memoryBlock | A region of the virtual memory. |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | The length or the offset of |
See Also
View SourceFromPointer<T>(T*, int)
Wraps unmanaged pointer to Memory<T>.
Declaration
[CLSCompliant(false)]
public static Memory<T> FromPointer<T>(T* pointer, int length) where T : unmanaged
Parameters
| Type | Name | Description |
|---|---|---|
| T* | pointer | The pointer to a sequence of elements. |
| int | length | The number of elements. |
Returns
| Type | Description |
|---|---|
| Memory<T> | The memory block that represents the data located at the pointer. |
Type Parameters
| Name | Description |
|---|---|
| T |
GetPageAlignedOffset(ReadOnlySpan<byte>, out int)
Calculates the page aligned offset for the specified memory block.
Declaration
public static bool GetPageAlignedOffset(ReadOnlySpan<byte> memory, out int offset)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | memory | The memory block. |
| int | offset | The offset to the page-aligned element. |
Returns
| Type | Description |
|---|---|
| bool | true if the |
get_UnmanagedZeroMem<T>()
Gets the unmanaged memoir
Declaration
public static MemoryAllocator<T> get_UnmanagedZeroMem<T>() where T : unmanaged
Returns
| Type | Description |
|---|---|
| MemoryAllocator<T> |
Type Parameters
| Name | Description |
|---|---|
| T |
get_Unmanaged<T>()
Gets the unmanaged memory allocator.
Declaration
public static MemoryAllocator<T> get_Unmanaged<T>() where T : unmanaged
Returns
| Type | Description |
|---|---|
| MemoryAllocator<T> |
Type Parameters
| Name | Description |
|---|---|
| T |