Documentation ¶
Overview ¶
Package mem provides reference-counted buffer and ways to work with memory as either string or []byte without copying.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Buf ¶
type Buf struct { Data []byte // contains filtered or unexported fields }
Buf is reference-counted memory buffer.
To lower pressure on Go garbage-collector allocate buffers with BufAlloc and free them with Buf.Release.
Custom allocation functions affect only performance, not correctness - everything should work if data buffer is allocated and/or free'ed via regular Go/GC-way.
func BufAlloc ¶
BufAlloc allocates buffer of requested size from freelist.
buffer memory is not initialized.
func BufAlloc64 ¶
BufAlloc64 is same as BufAlloc but accepts int64 for size.
func (*Buf) Cap ¶
Cap returns buf's cap.
it works even if buf=nil similarly to len() on nil []byte slice.
func (*Buf) Incref ¶
func (buf *Buf) Incref()
Incref increments buf's reference counter by 1.
buf must already have reference-counter > 0 before Incref call.
func (*Buf) Len ¶
Len returns buf's len.
it works even if buf=nil similarly to len() on nil []byte slice.
func (*Buf) Release ¶
func (buf *Buf) Release()
Release marks buf as no longer used by caller.
It decrements buf reference-counter and if it reaches zero returns buf to freelist.
The caller must not use buf after call to Release.