Show / Hide Table of Contents

Class UnmanagedMemory

Provides native memory allocation facilities.

Inheritance
object
UnmanagedMemory
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: DotNext.Buffers
Assembly: DotNext.Unsafe.dll
Syntax
public static class UnmanagedMemory

Methods

| Edit this page View Source

AllocatePageAlignedMemory(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 size to the page size; otherwise, false.

Returns
Type Description
IMemoryOwner<byte>

A memory owner that represents page-aligned memory block.

Exceptions
Type Condition
ArgumentOutOfRangeException

size is negative or zero.

| Edit this page View Source

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

pageCount is negative or zero.

| Edit this page View Source

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

The type of the elements in the unmanaged memory block.

Exceptions
Type Condition
ArgumentOutOfRangeException

length is less than or equal to zero.

| Edit this page View Source

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

The type of the elements in the unmanaged memory block.

Exceptions
Type Condition
ArgumentOutOfRangeException

length is less than or equal to zero.

| Edit this page View Source

AsMemory<T>(T*, int)

Wraps unmanaged pointer to Memory<T>.

Declaration
[CLSCompliant(false)]
public static Memory<T> AsMemory<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>
Type Parameters
Name Description
T

The type of elements in the memory.

| Edit this page View Source

GetAllocator<T>(bool)

Gets allocator of unmanaged memory.

Declaration
public static MemoryAllocator<T> GetAllocator<T>(bool zeroMem) where T : unmanaged
Parameters
Type Name Description
bool zeroMem

true to set all bits in the memory to zero; otherwise, false.

Returns
Type Description
MemoryAllocator<T>

The unmanaged memory allocator.

Type Parameters
Name Description
T

The type of the elements in the memory block.

  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾