# ComputeBuffer

> Create a Compute Buffer.

## Definition

* **Type:** Constructor
* **Namespace:** [UnityEngine](/engine/6000.0/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

## ComputeBuffer(int, int)

Create a Compute Buffer.

```csharp
public ComputeBuffer(int count, int stride)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of elements in the buffer.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Size of one element in the buffer, in bytes. Must be a multiple of 4 and less than 2048, and match the size of the buffer type in the shader. See [Compute Shaders](/engine/6000.0/manual/materials-and-shaders/shaders/writing-custom/class-compute-shader.md) for cross-platform compatibility information.

### Remarks

Use [ComputeBuffer.Release](/engine/6000.0/script-reference/unityengine/computebuffer/release.md) to release the buffer when no longer needed.

Additional Resources: [SystemInfo.supportsComputeShaders](/engine/6000.0/script-reference/unityengine/systeminfo/supportscomputeshaders.md), [ComputeShader](/engine/6000.0/script-reference/unityengine/computeshader.md) class, [Shader.SetGlobalBuffer](/engine/6000.0/script-reference/unityengine/shader/setglobalbuffer.md), [Material.SetBuffer](/engine/6000.0/script-reference/unityengine/material/setbuffer.md), [Compute Shaders](/engine/6000.0/manual/materials-and-shaders/shaders/writing-custom/class-compute-shader.md).

## ComputeBuffer(int, int, ComputeBufferType)

Create a Compute Buffer.

```csharp
public ComputeBuffer(int count, int stride, ComputeBufferType type)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of elements in the buffer.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Size of one element in the buffer, in bytes. Must be a multiple of 4 and less than 2048, and match the size of the buffer type in the shader. See [Compute Shaders](/engine/6000.0/manual/materials-and-shaders/shaders/writing-custom/class-compute-shader.md) for cross-platform compatibility information.**** (\[ComputeBufferType]\(/engine/6000.0/script-reference/unityengine/computebuffertype)): Type of the buffer, default is [ComputeBufferType.Default](/engine/6000.0/script-reference/unityengine/computebuffertype/default.md) (structured buffer).

### Remarks

Use [ComputeBuffer.Release](/engine/6000.0/script-reference/unityengine/computebuffer/release.md) to release the buffer when no longer needed.

Additional Resources: [SystemInfo.supportsComputeShaders](/engine/6000.0/script-reference/unityengine/systeminfo/supportscomputeshaders.md), [ComputeShader](/engine/6000.0/script-reference/unityengine/computeshader.md) class, [Shader.SetGlobalBuffer](/engine/6000.0/script-reference/unityengine/shader/setglobalbuffer.md), [Material.SetBuffer](/engine/6000.0/script-reference/unityengine/material/setbuffer.md), [Compute Shaders](/engine/6000.0/manual/materials-and-shaders/shaders/writing-custom/class-compute-shader.md).

## ComputeBuffer(int, int, ComputeBufferType, ComputeBufferMode)

Create a Compute Buffer.

```csharp
public ComputeBuffer(int count, int stride, ComputeBufferType type, ComputeBufferMode usage)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of elements in the buffer.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Size of one element in the buffer, in bytes. Must be a multiple of 4 and less than 2048, and match the size of the buffer type in the shader. See [Compute Shaders](/engine/6000.0/manual/materials-and-shaders/shaders/writing-custom/class-compute-shader.md) for cross-platform compatibility information.**** (\[ComputeBufferType]\(/engine/6000.0/script-reference/unityengine/computebuffertype)): Type of the buffer, default is [ComputeBufferType.Default](/engine/6000.0/script-reference/unityengine/computebuffertype/default.md) (structured buffer).**** (\[ComputeBufferMode]\(/engine/6000.0/script-reference/unityengine/computebuffermode)): Usage mode of the buffer, default is [ComputeBufferModeImmutable](/engine/6000.0/script-reference/unityengine/computebuffermode/immutable.md).

### Remarks

Use [ComputeBuffer.Release](/engine/6000.0/script-reference/unityengine/computebuffer/release.md) to release the buffer when no longer needed.

Additional Resources: [SystemInfo.supportsComputeShaders](/engine/6000.0/script-reference/unityengine/systeminfo/supportscomputeshaders.md), [ComputeShader](/engine/6000.0/script-reference/unityengine/computeshader.md) class, [Shader.SetGlobalBuffer](/engine/6000.0/script-reference/unityengine/shader/setglobalbuffer.md), [Material.SetBuffer](/engine/6000.0/script-reference/unityengine/material/setbuffer.md), [Compute Shaders](/engine/6000.0/manual/materials-and-shaders/shaders/writing-custom/class-compute-shader.md).
