Rediger

Del via


NativeMemory.AllocZeroed Method

Definition

Overloads

AllocZeroed(UIntPtr)

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

AllocZeroed(UIntPtr, UIntPtr)

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

AllocZeroed(UIntPtr)

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

Important

This API is not CLS-compliant.

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

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

Parameters

byteCount
UIntPtr

nuint

unativeint

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

Returns

Void*

A pointer to the allocated and zeroed 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 calloc API.

Applies to

AllocZeroed(UIntPtr, UIntPtr)

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

Important

This API is not CLS-compliant.

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

public:
 static void* AllocZeroed(UIntPtr elementCount, UIntPtr elementSize);
[System.CLSCompliant(false)]
public static void* AllocZeroed (nuint elementCount, nuint elementSize);
[System.CLSCompliant(false)]
public static void* AllocZeroed (UIntPtr elementCount, UIntPtr elementSize);
[<System.CLSCompliant(false)>]
static member AllocZeroed : 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 and zeroed block of memory.

Attributes

Exceptions

Allocating elementCount * elementSize bytes of memory failed.

Remarks

This method allows elementCount and elementSize to be 0. It returns 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 calloc API.

Applies to