Rediger

Del via


NativeMemory.Alloc Method

Definition

Overloads

Alloc(UIntPtr)

Allocates a block of memory of the specified size, in bytes.

Alloc(UIntPtr, UIntPtr)

Allocates a block of memory of the specified size, in elements.

Alloc(UIntPtr)

Source:
NativeMemory.Unix.cs
Source:
NativeMemory.Unix.cs
Source:
NativeMemory.Unix.cs

Important

This API is not CLS-compliant.

Allocates a block of memory of the specified size, in bytes.

public:
 static void* Alloc(UIntPtr byteCount);
[System.CLSCompliant(false)]
public static void* Alloc (nuint byteCount);
[System.CLSCompliant(false)]
public static void* Alloc (UIntPtr byteCount);
[<System.CLSCompliant(false)>]
static member Alloc : unativeint -> nativeptr<unit>

Parameters

byteCount
UIntPtr

nuint

unativeint

The size, in bytes, of the block to allocate.

Returns

Void*

A pointer to the allocated block of memory.

Attributes

Exceptions

Allocating byteCount of memory failed.

Remarks

This method allows byteCount to be 0 and will return a valid pointer that should not be dereferenced and that should be passed to free to avoid memory leaks.

This method is a thin wrapper over the C malloc API.

Applies to

Alloc(UIntPtr, UIntPtr)

Source:
NativeMemory.cs
Source:
NativeMemory.cs
Source:
NativeMemory.cs

Important

This API is not CLS-compliant.

Allocates a block of memory of the specified size, in elements.

public:
 static void* Alloc(UIntPtr elementCount, UIntPtr elementSize);
[System.CLSCompliant(false)]
public static void* Alloc (nuint elementCount, nuint elementSize);
[System.CLSCompliant(false)]
public static void* Alloc (UIntPtr elementCount, UIntPtr elementSize);
[<System.CLSCompliant(false)>]
static member Alloc : unativeint * unativeint -> nativeptr<unit>

Parameters

elementCount
UIntPtr

nuint

unativeint

The count, in elements, of the block to allocate.

elementSize
UIntPtr

nuint

unativeint

The size, in bytes, of each element in the allocation.

Returns

Void*

A pointer to the allocated block of memory.

Attributes

Exceptions

Allocating elementCount * elementSize bytes of memory failed.

Remarks

This method allows elementCount and/or elementSize to be 0 and will return a valid pointer that should not be dereferenced and that should be passed to free to avoid memory leaks.

This method is a thin wrapper over the C malloc API.

Applies to