buffer

package
v0.24.3 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SIZE_1B    = 1 << 0  // 1 byte
	SIZE_2B    = 1 << 1  // 2 bytes
	SIZE_4B    = 1 << 2  // 4 bytes
	SIZE_8B    = 1 << 3  // 8 bytes
	SIZE_16B   = 1 << 4  // 16 bytes
	SIZE_32B   = 1 << 5  // 32 bytes
	SIZE_64B   = 1 << 6  // 64 bytes
	SIZE_128B  = 1 << 7  // 128 bytes
	SIZE_256B  = 1 << 8  // 256 bytes
	SIZE_512B  = 1 << 9  // 512 bytes
	SIZE_1KB   = 1 << 10 // 1 kilobyte (1024 bytes)
	SIZE_2KB   = 1 << 11 // 2 kilobytes
	SIZE_4KB   = 1 << 12 // 4 kilobytes
	SIZE_8KB   = 1 << 13 // 8 kilobytes
	SIZE_16KB  = 1 << 14 // 16 kilobytes
	SIZE_32KB  = 1 << 15 // 32 kilobytes
	SIZE_64KB  = 1 << 16 // 64 kilobytes
	SIZE_128KB = 1 << 17 // 128 kilobytes
	SIZE_256KB = 1 << 18 // 256 kilobytes
	SIZE_512KB = 1 << 19 // 512 kilobytes
	SIZE_1MB   = 1 << 20 // 1 megabyte (1024 kilobytes)
)

Constants for buffer sizes in bytes, kilobytes, and megabytes. These constants are defined using bitwise left shift operations to represent power-of-two sizes, commonly used in computing for buffer sizes.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

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

Pool represents a pool of byte slices. It provides functionality to get and put byte slices to avoid frequent allocation and deallocation, which can improve performance in scenarios where byte slices of a fixed size are repeatedly used.

func ExistPool

func ExistPool(size int32) *Pool

ExistPool checks for the existence of a Pool for the given buffer size. It returns the Pool if it exists in bufferPools, otherwise nil.

Parameters: - size: int32 The size of the buffer pool to look for.

Returns: - *Pool: The existing buffer pool, or nil if not found.

func GetPool

func GetPool(size int32) *Pool

GetPool retrieves or creates a Pool for the given buffer size. It ensures thread-safe access to the bufferPools. If a Pool does not exist for the given size, it is created and added to bufferPools.

Parameters: - size: int32 The size of the buffer pool to retrieve or create.

Returns: - *Pool: A buffer pool for the given size.

func (*Pool) Get

func (p *Pool) Get() *[]byte

Get retrieves a pointer to a byte slice from the pool. It returns a pre-allocated byte slice pointer from the pool, reducing the need for memory allocation.

Output: - *[]byte: A pointer to a byte slice from the pool.

func (*Pool) Put

func (p *Pool) Put(x *[]byte)

Put returns a pointer to a byte slice to the pool. This method is used to return a used byte slice pointer back to the pool for reuse, aiding in efficient memory management.

Input: - x *[]byte: The pointer to the byte slice to be returned to the pool.

Jump to

Keyboard shortcuts

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