Documentation
¶
Index ¶
- Variables
- func GetBufferForSize(size int) []byte
- func GetLargeBuffer() []byte
- func GetMediumBuffer() []byte
- func GetSmallBuffer() []byte
- func PutBufferForSize(buf []byte)
- func PutLargeBuffer(buf []byte)
- func PutMediumBuffer(buf []byte)
- func PutSmallBuffer(buf []byte)
- func VarIntDecode(flag byte, bbf buf.ByteBuf) uint64
- func VarIntEncode(val uint64) buf.ByteBuf
- type BufferPool
- type MockQueue
- type Queue
Constants ¶
This section is empty.
Variables ¶
var ( // SmallBufferPool for small buffers (4KB) - typical for network I/O, headers, small messages SmallBufferPool = NewBufferPool(4 * 1024) // MediumBufferPool for medium buffers (16KB) - good for most application data MediumBufferPool = NewBufferPool(16 * 1024) // LargeBufferPool for large buffers (64KB) - for UDP max packet size, large transfers LargeBufferPool = NewBufferPool(64 * 1024) )
Global buffer pools for common sizes
Functions ¶
func GetBufferForSize ¶ added in v1.9.0
GetBufferForSize returns the most appropriate clean buffer for the given size This helps choose the right pool automatically based on size requirements
func GetLargeBuffer ¶ added in v1.9.0
func GetLargeBuffer() []byte
GetLargeBuffer gets a clean 64KB buffer from the large buffer pool
func GetMediumBuffer ¶ added in v1.9.0
func GetMediumBuffer() []byte
GetMediumBuffer gets a clean 16KB buffer from the medium buffer pool
func GetSmallBuffer ¶ added in v1.9.0
func GetSmallBuffer() []byte
GetSmallBuffer gets a clean 4KB buffer from the small buffer pool
func PutBufferForSize ¶ added in v1.9.0
func PutBufferForSize(buf []byte)
PutBufferForSize returns a buffer to the appropriate pool based on its size
func PutLargeBuffer ¶ added in v1.9.0
func PutLargeBuffer(buf []byte)
PutLargeBuffer returns a 64KB buffer to the large buffer pool
func PutMediumBuffer ¶ added in v1.9.0
func PutMediumBuffer(buf []byte)
PutMediumBuffer returns a 16KB buffer to the medium buffer pool
func PutSmallBuffer ¶ added in v1.9.0
func PutSmallBuffer(buf []byte)
PutSmallBuffer returns a 4KB buffer to the small buffer pool
func VarIntDecode ¶ added in v1.9.0
VarIntDecode decodes a variable-length encoded value from a ByteBuf
func VarIntEncode ¶ added in v1.9.0
VarIntEncode encodes a uint64 value using variable-length encoding
Types ¶
type BufferPool ¶ added in v1.9.0
type BufferPool struct {
// contains filtered or unexported fields
}
BufferPool provides a thread-safe pool for byte buffers of different sizes This helps reduce memory allocations and GC pressure for frequently used buffers
func NewBufferPool ¶ added in v1.9.0
func NewBufferPool(size int) *BufferPool
NewBufferPool creates a new buffer pool with the specified buffer size
func (*BufferPool) Get ¶ added in v1.9.0
func (bp *BufferPool) Get() []byte
Get retrieves a buffer from the pool and clears it to prevent dirty data Returns a clean byte slice of the pool's configured size
func (*BufferPool) GetWithSize ¶ added in v1.9.0
func (bp *BufferPool) GetWithSize(size int) []byte
GetWithSize retrieves a buffer and resizes it if needed If the requested size is larger than the pool buffer, it creates a new buffer This provides flexibility while still benefiting from pooling for common sizes
func (*BufferPool) Put ¶ added in v1.9.0
func (bp *BufferPool) Put(buf []byte)
Put returns a buffer to the pool for reuse The buffer should be of the same size as the pool's configured size
func (*BufferPool) Size ¶ added in v1.9.0
func (bp *BufferPool) Size() int
Size returns the configured buffer size for this pool
type MockQueue ¶ added in v1.9.0
MockQueue is a mock implementation of Queue for testing
func NewMockQueue ¶ added in v1.9.0
func NewMockQueue() *MockQueue
NewMockQueue creates a new MockQueue instance
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue provides a thread-safe FIFO queue implementation Safe for concurrent access from multiple goroutines
func (*Queue) Pop ¶
Pop removes and returns the oldest item from the queue Returns nil if the queue is empty Thread-safe for concurrent use