Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


CreateBuffer(ulong, ulong)

Allocates a new buffer on the device with the specified element count and stride.
Read time 1 minuteLast updated 6 days ago

Definition

BufferID CreateBuffer(ulong count, ulong stride)

Parameters

count

Number of elements in the buffer.

stride

Size of each element in bytes.

Returns

Type

Description

BufferIDUnique identifier for the newly created buffer.

Remarks

Creates a buffer that can store the specified number of elements, each with the given stride (size in bytes). The actual memory allocation may occur in CPU memory, GPU memory, or unified memory depending on the hardware platform and implementation.
The returned BufferID can be used to create typed BufferSlice objects for reading and writing data.
Note: Buffers must be destroyed using IDeviceContext.DestroyBuffer to avoid memory leaks.

Examples

// Create a buffer for 1000 integersBufferID bufferId = context.CreateBuffer(1000, sizeof(int));var intSlice = new BufferSlice<int>(bufferId, 0);// Create a buffer for 500 Vector3 structuresBufferID vectorBuffer = context.CreateBuffer(500, 12); // size is 3 floats * 4 bytesvar vectorSlice = new BufferSlice<Vector3>(vectorBuffer, 0);