Documentation ¶
Overview ¶
Package alloc provides a light-weight memory allocation mechanism.
Index ¶
- Constants
- type Buffer
- func (b *Buffer) Append(data []byte) *Buffer
- func (b *Buffer) AppendBytes(bytes ...byte) *Buffer
- func (b *Buffer) AppendString(s string) *Buffer
- func (b *Buffer) AppendUint16(val uint16) *Buffer
- func (b *Buffer) AppendUint32(val uint32) *Buffer
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Clear() *Buffer
- func (b *Buffer) FillFrom(reader io.Reader) (int, error)
- func (b *Buffer) IsEmpty() bool
- func (b *Buffer) IsFull() bool
- func (b *Buffer) Len() int
- func (b *Buffer) Prepend(data []byte) *Buffer
- func (b *Buffer) PrependBytes(data ...byte) *Buffer
- func (b *Buffer) PrependHash(h hash.Hash) *Buffer
- func (b *Buffer) PrependUint16(val uint16) *Buffer
- func (b *Buffer) PrependUint32(val uint32) *Buffer
- func (b *Buffer) Read(data []byte) (int, error)
- func (b *Buffer) Release()
- func (b *Buffer) Reset() *Buffer
- func (b *Buffer) Slice(from, to int) *Buffer
- func (b *Buffer) SliceBack(offset int) *Buffer
- func (b *Buffer) SliceFrom(from int) *Buffer
- func (b *Buffer) String() string
- func (b *Buffer) Write(data []byte) (int, error)
- type BufferPool
- type Pool
- type SyncPool
Constants ¶
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 NewBuffer ¶
func NewBuffer() *Buffer
NewBuffer creates a Buffer with 8K bytes of arbitrary content.
func (*Buffer) Append ¶
Append appends a byte array to the end of the buffer.
func (*Buffer) AppendBytes ¶
AppendBytes appends one or more bytes to the end of the buffer.
func (*Buffer) AppendString ¶ added in v1.12.1
AppendString appends a given string to the end of the buffer.
func (*Buffer) Bytes ¶ added in v1.9.1
Bytes returns the content bytes of this Buffer.
func (*Buffer) Clear ¶
Clear clears the content of the buffer, results an empty buffer with Len() = 0.
func (*Buffer) IsFull ¶
IsFull returns true if the buffer has no more room to grow.
func (*Buffer) Prepend ¶ added in v1.9.1
Prepend prepends bytes in front of the buffer. Caller must ensure total bytes prepended is no more than 16 bytes.
func (*Buffer) Read ¶ added in v1.9.1
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
Reset resets this Buffer into its original state.
func (*Buffer) Slice ¶
Slice cuts the buffer at the given position.
func (*Buffer) SliceBack ¶ added in v1.9.1
SliceBack extends the Buffer to its front by offset bytes. Caller must ensure cumulated offset is no more than 16.
func (*Buffer) SliceFrom ¶
SliceFrom cuts the buffer at the given position.
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)