ringbuffer

package
v0.4.0-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Copyright (c) 2023 Paweł Gaczyński Copyright (c) 2019 Andy Pan Copyright (c) 2016 Aliaksandr Valialkin, VertaMedia

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Use of this source code is governed by a MIT license that can be found at https://github.com/valyala/bytebufferpool/blob/master/LICENSE

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Put

func Put(b *RingBuffer)

Put returns byte buffer to the pool.

RingBuffer mustn't be touched after returning it to the pool, otherwise, data races will occur.

Types

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool represents ring-buffer pool.

Distinct pools may be used for distinct types of byte buffers. Properly determined byte buffer types with their own pools may help to reduce memory waste.

func NewRingBufferPool

func NewRingBufferPool() Pool

func (*Pool) Get

func (p *Pool) Get() *RingBuffer

Get returns new byte buffer with zero length.

The byte buffer may be returned to the pool via Put after the use in order to minimize GC overhead.

func (*Pool) Put

func (p *Pool) Put(buffer *RingBuffer)

Put releases byte buffer obtained via Get to the pool.

The buffer mustn't be accessed after returning to the pool.

type RingBuffer

type RingBuffer = magicring.RingBuffer

RingBuffer is the alias of ring.Buffer.

func Get

func Get() *RingBuffer

Get returns an empty byte buffer from the pool.

Got byte buffer may be returned to the pool via Put call. This reduces the number of memory allocations required for byte buffer management.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL