alloc

package
v2.8.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2016 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package alloc provides a light-weight memory allocation mechanism.

Index

Constants

View Source
const (
	BufferSize = mediumBufferByteSize - defaultOffset

	SmallBufferSize = smallBufferByteSize - defaultOffset

	PoolSizeEnvKey = "v2ray.buffer.size"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	Value []byte
	// contains filtered or unexported fields
}

Buffer is a recyclable allocation of a byte array. Buffer.Release() recycles the buffer into an internal buffer pool, in order to recreate a buffer more quickly.

func CreateBuffer added in v1.21.1

func CreateBuffer(container []byte, parent Pool) *Buffer

func NewBuffer

func NewBuffer() *Buffer

NewBuffer creates a Buffer with 8K bytes of arbitrary content.

func NewLocalBuffer added in v1.21.1

func NewLocalBuffer(size int) *Buffer

func NewSmallBuffer

func NewSmallBuffer() *Buffer

func (*Buffer) Append

func (b *Buffer) Append(data []byte) *Buffer

Append appends a byte array to the end of the buffer.

func (*Buffer) AppendBytes

func (b *Buffer) AppendBytes(bytes ...byte) *Buffer

AppendBytes appends one or more bytes to the end of the buffer.

func (*Buffer) AppendString added in v1.12.1

func (b *Buffer) AppendString(s string) *Buffer

AppendString appends a given string to the end of the buffer.

func (*Buffer) AppendUint16 added in v1.17.3

func (b *Buffer) AppendUint16(val uint16) *Buffer

func (*Buffer) AppendUint32 added in v1.17.3

func (b *Buffer) AppendUint32(val uint32) *Buffer

func (*Buffer) Bytes added in v1.9.1

func (b *Buffer) Bytes() []byte

Bytes returns the content bytes of this Buffer.

func (*Buffer) Clear

func (b *Buffer) Clear() *Buffer

Clear clears the content of the buffer, results an empty buffer with Len() = 0.

func (*Buffer) FillFrom added in v1.9.1

func (b *Buffer) FillFrom(reader io.Reader) (int, error)

func (*Buffer) IsEmpty added in v1.9.1

func (b *Buffer) IsEmpty() bool

func (*Buffer) IsFull

func (b *Buffer) IsFull() bool

IsFull returns true if the buffer has no more room to grow.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the length of the buffer content.

func (*Buffer) Prepend added in v1.9.1

func (b *Buffer) Prepend(data []byte) *Buffer

Prepend prepends bytes in front of the buffer. Caller must ensure total bytes prepended is no more than 16 bytes.

func (*Buffer) PrependBytes added in v1.17.3

func (b *Buffer) PrependBytes(data ...byte) *Buffer

func (*Buffer) PrependHash added in v1.21.1

func (b *Buffer) PrependHash(h hash.Hash) *Buffer

func (*Buffer) PrependUint16 added in v1.17.3

func (b *Buffer) PrependUint16(val uint16) *Buffer

func (*Buffer) PrependUint32 added in v1.17.3

func (b *Buffer) PrependUint32(val uint32) *Buffer

func (*Buffer) Read added in v1.9.1

func (b *Buffer) Read(data []byte) (int, error)

Read implements io.Reader.Read().

func (*Buffer) Release

func (b *Buffer) Release()

Release recycles the buffer into an internal buffer pool.

func (*Buffer) Reset added in v1.19.1

func (b *Buffer) Reset() *Buffer

Reset resets this Buffer into its original state.

func (*Buffer) Slice

func (b *Buffer) Slice(from, to int) *Buffer

Slice cuts the buffer at the given position.

func (*Buffer) SliceBack added in v1.9.1

func (b *Buffer) SliceBack(offset int) *Buffer

SliceBack extends the Buffer to its front by offset bytes. Caller must ensure cumulated offset is no more than 16.

func (*Buffer) SliceFrom

func (b *Buffer) SliceFrom(from int) *Buffer

SliceFrom cuts the buffer at the given position.

func (*Buffer) String added in v1.12.1

func (b *Buffer) String() string

func (*Buffer) Write

func (b *Buffer) Write(data []byte) (int, error)

Write implements Write method in io.Writer.

type BufferPool added in v1.11.1

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

func NewBufferPool added in v1.11.1

func NewBufferPool(bufferSize, poolSize uint32) *BufferPool

func (*BufferPool) Allocate added in v1.11.1

func (p *BufferPool) Allocate() *Buffer

func (*BufferPool) Free added in v1.11.1

func (p *BufferPool) Free(buffer *Buffer)

type Pool added in v1.23.1

type Pool interface {
	Allocate() *Buffer
	Free(*Buffer)
}

type SyncPool

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

func NewSyncPool

func NewSyncPool(bufferSize uint32) *SyncPool

func (*SyncPool) Allocate

func (p *SyncPool) Allocate() *Buffer

func (*SyncPool) Free

func (p *SyncPool) Free(buffer *Buffer)

Jump to

Keyboard shortcuts

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