github.com/tobgu/qframe@v0.4.0/internal/strings/pointer.go (about) 1 package strings 2 3 import "fmt" 4 5 // Pointer identifies a string within a StringBlob. 6 // Max individual string size 2^28 byte ~ 268 Mb 7 // Max total size 2^35 byte ~ 34 Gb 8 type Pointer uint64 9 10 // StringBlob represents a set of strings. 11 // The underlying data is stored in a byte blob which can be interpreted through 12 // the pointers which identifies the start and end of individual strings in the blob. 13 // 14 // This structure is used instead of a slice of strings or a slice of 15 // string pointers is to avoid that the GC has to scan all pointers which 16 // takes quite some time with large/many live frames. 17 type StringBlob struct { 18 Pointers []Pointer 19 Data []byte 20 } 21 22 const nullBit = 0x8000000000000000 23 24 func NewPointer(offset, length int, isNull bool) Pointer { 25 result := Pointer(offset<<28 | length) 26 if isNull { 27 result |= nullBit 28 } 29 return result 30 } 31 32 func (p Pointer) Offset() int { 33 return int(p>>28) & 0x7FFFFFFFF 34 } 35 36 func (p Pointer) Len() int { 37 return int(p) & 0xFFFFFFF 38 } 39 40 func (p Pointer) IsNull() bool { 41 return p&nullBit > 0 42 } 43 44 func (p Pointer) String() string { 45 return fmt.Sprintf("{offset: %d, len: %d, isNull: %v}", 46 p.Offset(), p.Len(), p.IsNull()) 47 }