Documentation
¶
Overview ¶
Package intern stores each distinct string once, off the Go heap, and names it with a 4-byte Symbol. Repeated text, such as field names or log labels, then costs one copy, and comparing two Symbols is comparing two integers.
Example ¶
package main
import (
"fmt"
memory "github.com/stubbedev/memory-go"
"github.com/stubbedev/memory-go/intern"
)
func main() {
var a memory.Local
defer a.Close()
t, err := intern.New(&a)
if err != nil {
panic(err)
}
first, _ := t.Intern("status")
second, _ := t.Intern("status")
fmt.Println(first == second, t.Text(first))
}
Output: true status
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Symbol ¶
type Symbol uint32
Symbol names an interned string in four bytes and may be stored off-heap. The zero Symbol is nil.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table holds interned strings until Free. It is not safe for concurrent use.