Method Alloc
Alloc(nuint)
Allocates a block of memory of the specified size, in bytes (分配指定大小的内存块(以字节为单位)).
[CLSCompliant(false)]
public static void* Alloc(nuint byteCount)
Parameters
byteCount
nuintThe size, in bytes, of the block to allocate (要分配的块的大小(以字节为单位)).
Returns
- void*
A pointer to the allocated block of memory (指向分配的内存块的指针).
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 (此方法允许 byteCount 为 0 ,将返回一个有效的指针, 该指针不应被取消引用, 应传递给 free 以避免内存泄漏).
This method is a thin wrapper over the C malloc
API (此方法是 C malloc API 上的精简包装器).
Exceptions
- OutOfMemoryException
Allocating
byteCount
of memory failed.
Alloc(nuint, nuint)
Allocates a block of memory of the specified size, in elements (按元素分配指定大小的内存块).
[CLSCompliant(false)]
public static void* Alloc(nuint elementCount, nuint elementSize)
Parameters
elementCount
nuintThe count, in elements, of the block to allocate (要分配的块的数量(以元素为单位)).
elementSize
nuintThe size, in bytes, of each element in the allocation (分配中每个元素的大小(以字节为单位)).
Returns
- void*
A pointer to the allocated block of memory (指向分配的内存块的指针).
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 (此方法允许 elementCount/ elementSize 为 0 ,将返回一个有效的指针, 该指针不应被取消引用, 应传递给 free 以避免内存泄漏).
This method is a thin wrapper over the C malloc
API (此方法是 C malloc API 上的精简包装器).
Exceptions
- OutOfMemoryException
Allocating
elementCount
*elementSize
bytes of memory failed.