# ChunkDataPool

Interface

Source: https://github.com/playcanvas/splat-transform/blob/b6424a5b3b929695fbaafe738a995adb1240d675/src/lib/chunk/pool.ts#L25

A pool-backed allocator for [ChunkData](https://api.playcanvas.com/splat-transform/interfaces/ChunkData.md) buffers.

The pool owns a single `chunkSize` (the gaussians-per-chunk granularity);
every buffer it hands out is backed by an `ArrayBuffer` of full capacity
(`chunkSize * stride`). A short final chunk's buffer therefore shares a pool
slot with full-chunk buffers of the same layer stride — the pool keys on the
buffer's byte size, so reuse is by capacity, not by the (possibly smaller)
`count`.

No `GraphicsDevice` is required: these are CPU buffers. A consumer that needs
GPU-resident data uploads `chunkData.data` itself.

Pool growth is bounded by `maxPooledBytes` (default 2 GB). On release, if
pooling the buffer would exceed the cap, it is dropped (left to the garbage
collector) instead. Call [ChunkDataPool.trim](https://api.playcanvas.com/splat-transform/interfaces/ChunkDataPool.md#trim) to free pooled buffers
down to a target.

## Properties

### bytesInUse

```ts
readonly bytesInUse: number
```

Total bytes currently held by callers (not in the pool).

### bytesPooled

```ts
readonly bytesPooled: number
```

Total bytes free-listed and ready to be reused.

### chunkSize

```ts
readonly chunkSize: number
```

Gaussians-per-chunk granularity this pool allocates for.

## Methods

### acquire

```ts
acquire(layer: ChunkLayer, layout: LayerLayout, count: number): ChunkData
```

Acquire a [ChunkData](https://api.playcanvas.com/splat-transform/interfaces/ChunkData.md) buffer for the given layer/layout holding
`count` gaussians of valid data (`0 < count <= chunkSize`). Reuses a
pooled buffer of matching capacity if available; otherwise allocates a
new one.

**Parameters**

- `layer` ([`ChunkLayer`](https://api.playcanvas.com/splat-transform/types/ChunkLayer.md))
- `layout` ([`LayerLayout`](https://api.playcanvas.com/splat-transform/types/LayerLayout.md))
- `count` (`number`)

**Returns** [`ChunkData`](https://api.playcanvas.com/splat-transform/interfaces/ChunkData.md)

### destroy

```ts
destroy(): void
```

Drop all pooled buffers. Buffers in use are unaffected.

### trim

```ts
trim(targetBytes: number): void
```

Free pooled buffers until `bytesPooled <= targetBytes`.

**Parameters**

- `targetBytes` (`number`)
