Documentation
¶
Index ¶
- func Alloc[T any](a Arena) *T
- func Append[S ~[]T, T any](a Arena, s S, item T) S
- func AppendN[S ~[]T, T any](a Arena, s S, items ...T) S
- func Bytes(a Arena, len int) []byte
- func Copy[S ~[]T, T any](a Arena, src S) S
- func CopyBytes(a Arena, src []byte) []byte
- func CopyBytesTo(a Arena, dst []byte, src []byte) []byte
- func Grow[S ~[]T, T any](a Arena, s S, capacity int) S
- func NewArenaRef() ref.R[Arena]
- func Slice[S ~[]T, T any](a Arena, len int, cap int) S
- func Slice1[S ~[]T, T any](a Arena, item T) S
- func String(a Arena, src string) string
- func StringBytes(a Arena, src []byte) string
- func StringFormat(a Arena, format string, args ...any) string
- func StringJoin(a Arena, src []string, sep string) string
- func StringJoin2(a Arena, s1, s2, sep string) string
- func StringRunes(a Arena, src []rune) string
- type Arena
- type Buffer
- type BufferPool
- type BufferedWriter
- type MutexArena
- type Pinned
- type Pool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Alloc ¶
Alloc allocates a new object and returns a pointer to it.
Usage:
var foo *float64 var bar *MyStruct foo = Alloc[float64](arena) bar = Alloc[MyStruct](arena)
func Append ¶
Append appends a new item to a slice, grows the slice if required, and returns the modified slice.
func AppendN ¶
AppendN appends a new slice to a slice, grows the slice if required, and returns the modified slice.
func Copy ¶
Copy allocates a new slice and copies items from src into it. The slice capacity is len(src).
func CopyBytes ¶
CopyBytes allocates a new byte slice and copies items from src into it. The slice capacity is len(src).
func CopyBytesTo ¶
CopyBytesTo copies bytes from src into dst, growing dst if needed.
func NewArenaRef ¶
NewArenaRef returns a reference to a new non-thread-safe arena.
func Slice ¶
Slice allocates a new slice of a generic type.
Usage:
s := Slice[[]MyStruct](arena, 0, 16)
func Slice1 ¶
Slice1 allocates a new slice with a single item.
Usage:
elem := 123 s := Slice[[]int](arena, elem)
func StringBytes ¶
StringBytes allocates a new string and copies data from src into it.
func StringFormat ¶
StringFormat formats a string using fmt.Appendf and returns a new string allocated in the arena.
func StringJoin ¶
StringJoin joins strings using separator.
func StringJoin2 ¶
StringJoin2 joins two strings using separator.
func StringRunes ¶
StringRunes allocates a new string and copies data from src into it.
Types ¶
type Arena ¶
Arena is an arena memory allocator. The arena must be freed after usage.
func AcquireArena ¶
func AcquireArena() Arena
AcquireArena returns a pooled arena, which is released to the pool on Free.
The arena must not be used or even referenced after Free. Use these method only when arenas do not escape an isolated scope.
Typical usage:
arena := alloc.AcquireArena() defer arena.Free() // free immediately
func NewMutexArena ¶
func NewMutexArena() Arena
NewMutexArena returns a new thread-safe arena which uses a mutex to synchronize access.
type Buffer ¶
Buffer is a buffer allocated by an allocator. The buffer must be freed after usage.
func AcquireBuffer ¶
func AcquireBuffer() Buffer
AcquireBuffer returns a new buffer from the pool.
The buffer must not be used or even referenced after Free. Use these method only when buffers do not escape an isolated scope.
Typical usage:
buf := alloc.AcquireBuffer() defer buf.Free() // free immediately
func NewBufferSize ¶
NewBuffer allocates a buffer of a preallocated capacity.
type BufferPool ¶
type BufferPool interface { // Get returns an empty pool. Get() buffer.Buffer // Put reset and puts a buffer back into the pool. // The buffer must be allocated in this pool. Put(buf buffer.Buffer) }
BufferPool is a pool of buffers allocated in the arena. It is thread-safe but only if backed by MutexArena. The pool itself is allocated in the arena.
func NewBufferPool ¶
func NewBufferPool(a Arena) BufferPool
NewBufferPool returns a new buffer pool which allocates buffers in the given arena.
type BufferedWriter ¶
Writer buffers small writes and flushes them to an underlying writer.
func NewBufferedWriter ¶
func NewBufferedWriter(dst io.Writer) BufferedWriter
NewBufferedWriter returns a new buffered writer with the default buffer size.
func NewBufferedWriterSize ¶
func NewBufferedWriterSize(dst io.Writer, size int) BufferedWriter
NewBufferedWriterSize returns a new buffered writer with the specified buffer size.
type MutexArena ¶
type MutexArena = arena.MutexArena
Arena is an arena memory allocator. The arena must be freed after usage.
type Pinned ¶
Pinned is a wrapper for an object pinned to an arena.
type Pool ¶
type Pool[T any] interface { // Get acquires an object and returns true, or allocates a new one and returns false. Get() (*T, bool) // Put puts an object back into the pool. // The object must be allocated in this pool. Put(obj *T) }
Pool is a pool of objects allocated in the arena. It is thread-safe but only if backed by MutexArena. The pool itself is allocated in the arena.