Back to godoc.org

Package mem

v0.0.0-...-3cf7f3f
Latest Go to latest

The latest major version is .

Published: May 27, 2020 | License: GPL3 | Module: lab.nexedi.com/kirr/go123

Overview

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

Index

func Bytes

func Bytes(s string) []byte

Bytes converts string -> []byte without copying

func String

func String(b []byte) string

String converts []byte -> string without copying

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

func BufAlloc(size int) *Buf

BufAlloc allocates buffer of requested size from freelist.

buffer memory is not initialized.

func BufAlloc64

func BufAlloc64(size int64) *Buf

BufAlloc64 is same as BufAlloc but accepts int64 for size.

func (*Buf) Cap

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

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

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

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

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

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

func (*Buf) XIncref

func (buf *Buf) XIncref()

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

func (*Buf) XRelease

func (buf *Buf) XRelease()

XRelease releases buf it is != nil.

Package Files

  • buffer.go
  • mem.go
Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier