# PooledBuffer Methods

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.buffers.pooledbuffer/)

## Advance(int) {#advance-int-39f52e20}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.buffers.pooledbuffer/methods/advance-int-39f52e20/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Buffers/PooledBuffer.cs#L73-L81)

```csharp
public void Advance(int bytes)
```

Notifies the `System.Buffers.IBufferWriter-1` that `count` data items were written to the output `System.Span-1` or `System.Memory-1`.

### Parameters

- `bytes` (`int`): The number of data items written to the `System.Span-1` or `System.Memory-1`.

## AsReadOnlySequence {#asreadonlysequence-251c8256}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.buffers.pooledbuffer/methods/asreadonlysequence-251c8256/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Buffers/PooledBuffer.cs#L189-L200)

```csharp
public ReadOnlySequence<byte> AsReadOnlySequence()
```

Returns a new `System.Buffers.ReadOnlySequence-1` which must not be accessed after disposing this instance.

## CopyTo(Span&lt;byte&gt;) {#copyto-system-span-byte-de39a79b}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.buffers.pooledbuffer/methods/copyto-system-span-byte-de39a79b/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Buffers/PooledBuffer.cs#L133-L148)

```csharp
public readonly void CopyTo(Span<byte> output)
```

Copies the contents of this writer to a span.

### Parameters

- `output` (`Span<byte>`)

## CopyTo(TBufferWriter) {#copyto-1-ref-tbufferwriter-d7d15908}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.buffers.pooledbuffer/methods/copyto-1-ref-tbufferwriter-d7d15908/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Buffers/PooledBuffer.cs)

```csharp
public readonly void CopyTo<TBufferWriter>(ref TBufferWriter writer)
```

Copies the contents of this writer to another writer.

### Parameters

- `writer` (`TBufferWriter`)

## CopyTo(Writer&lt;TBufferWriter&gt;) {#copyto-1-ref-orleans-serialization-buffers-writer-tbufferwriter-d7f03595}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.buffers.pooledbuffer/methods/copyto-1-ref-orleans-serialization-buffers-writer-tbufferwriter-d7f03595/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Buffers/PooledBuffer.cs)

```csharp
public readonly void CopyTo<TBufferWriter>(ref Writer<TBufferWriter> writer)
```

Copies the contents of this writer to another writer.

### Parameters

- `writer` (`Writer<TBufferWriter>`)

## Dispose {#dispose-14afdca3}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.buffers.pooledbuffer/methods/dispose-14afdca3/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Buffers/PooledBuffer.cs#L104)

```csharp
public void Dispose()
```

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

## GetMemory(int) {#getmemory-int-1bb3b5da}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.buffers.pooledbuffer/methods/getmemory-int-1bb3b5da/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Buffers/PooledBuffer.cs#L110-L115)

```csharp
public Memory<byte> GetMemory(int sizeHint = 0)
```

Returns a `System.Memory-1` to write to that is at least the requested size (specified by `sizeHint`).

### Parameters

- `sizeHint` (`int`): The minimum length of the returned `System.Memory-1`. If 0, a non-empty buffer is returned.

### Returns

A `System.Memory-1` of at least the size `sizeHint`. If `sizeHint` is 0, returns a non-empty buffer.

### Exceptions

- `System.OutOfMemoryException`: The requested buffer size is not available.

## GetSpan(int) {#getspan-int-c98bad48}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.buffers.pooledbuffer/methods/getspan-int-c98bad48/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Buffers/PooledBuffer.cs#L122-L127)

```csharp
public Span<byte> GetSpan(int sizeHint = 0)
```

Returns a `System.Span-1` to write to that is at least the requested size (specified by `sizeHint`).

### Parameters

- `sizeHint` (`int`): The minimum length of the returned `System.Span-1`. If 0, a non-empty buffer is returned.

### Returns

A `System.Span-1` of at least the size `sizeHint`. If `sizeHint` is 0, returns a non-empty buffer.

## Reset {#reset-731d2061}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.buffers.pooledbuffer/methods/reset-731d2061/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Buffers/PooledBuffer.cs#L88-L101)

```csharp
public void Reset()
```

Resets this instance, returning all memory.

## Slice {#slice-f5130950}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.buffers.pooledbuffer/methods/slice-f5130950/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Buffers/PooledBuffer.cs#L210)

```csharp
public readonly BufferSlice Slice()
```

Returns a [BufferSlice](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.buffers.pooledbuffer.bufferslice/) covering this entire buffer.

### Returns

A [BufferSlice](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.buffers.pooledbuffer.bufferslice/) covering this entire buffer.

## Slice(int) {#slice-int-901bdcc0}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.buffers.pooledbuffer/methods/slice-int-901bdcc0/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Buffers/PooledBuffer.cs#L219)

```csharp
public readonly BufferSlice Slice(int offset)
```

Returns a slice of this buffer, beginning at the specified offset.

### Parameters

- `offset` (`int`)

### Returns

A slice representing a subset of this instance, beginning at the specified offset.

## Slice(int, int) {#slice-int-int-8f45c54d}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.buffers.pooledbuffer/methods/slice-int-int-8f45c54d/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Buffers/PooledBuffer.cs#L228)

```csharp
public readonly BufferSlice Slice(int offset, int length)
```

Returns a slice of this buffer, beginning at the specified offset and having the specified length.

### Parameters

- `offset` (`int`)
- `length` (`int`)

### Returns

A slice representing a subset of this instance, beginning at the specified offset.

## ToArray {#toarray-938d787e}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.buffers.pooledbuffer/methods/toarray-938d787e/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Buffers/PooledBuffer.cs#L50-L66)

```csharp
public readonly byte[] ToArray()
```

Returns the data which has been written as an array.

### Returns

The data which has been written.

## Write(ReadOnlySequence&lt;byte&gt;) {#write-system-buffers-readonlysequence-byte-af0bece4}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.buffers.pooledbuffer/methods/write-system-buffers-readonlysequence-byte-af0bece4/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Buffers/PooledBuffer.cs#L243-L247)

```csharp
public void Write(ReadOnlySequence<byte> input)
```

Writes the provided sequence to this buffer.

### Parameters

- `input` (`ReadOnlySequence<byte>`): The data to write.

## Write(ReadOnlySpan&lt;byte&gt;) {#write-system-readonlyspan-byte-beb094a8}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.buffers.pooledbuffer/methods/write-system-readonlyspan-byte-beb094a8/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Buffers/PooledBuffer.cs#L257-L269)

```csharp
public void Write(ReadOnlySpan<byte> value)
```

Writes the provided value to this buffer.

### Parameters

- `value` (`ReadOnlySpan<byte>`): The data to write.
