go123: lab.nexedi.com/kirr/go123/mem Index | Files

package mem

import "lab.nexedi.com/kirr/go123/mem"

Package mem provides reference-counted buffer and ways to work with memory as either string or []byte without copying.


Package Files

buffer.go mem.go

func Bytes Uses

func Bytes(s string) []byte

Bytes converts string -> []byte without copying

func String Uses

func String(b []byte) string

String converts []byte -> string without copying

type Buf Uses

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 Uses

func BufAlloc(size int) *Buf

BufAlloc allocates buffer of requested size from freelist.

buffer memory is not initialized.

func BufAlloc64 Uses

func BufAlloc64(size int64) *Buf

BufAlloc64 is same as BufAlloc but accepts int64 for size.

func (*Buf) Cap Uses

func (buf *Buf) Cap() int

Cap returns buf's cap.

it works even if buf=nil similarly to len() on nil []byte slice.

func (*Buf) Incref Uses

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 Uses

func (buf *Buf) Len() int

Len returns buf's len.

it works even if buf=nil similarly to len() on nil []byte slice.

func (*Buf) Release Uses

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.

func (*Buf) XData Uses

func (buf *Buf) XData() []byte

XData return's buf.Data or nil if buf == nil.

func (*Buf) XIncref Uses

func (buf *Buf) XIncref()

XIncref increments buf's reference counter by 1 if buf != nil.

func (*Buf) XRelease Uses

func (buf *Buf) XRelease()

XRelease releases buf it is != nil.

Package mem imports 5 packages (graph) and is imported by 7 packages. Updated 2020-06-05. Refresh now. Tools for package owners.