-
Notifications
You must be signed in to change notification settings - Fork 5
/
slice.go
51 lines (39 loc) · 827 Bytes
/
slice.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2016 CodisLabs. All Rights Reserved.
// Licensed under the MIT (MIT-LICENSE.txt) license.
package unsafe2
import "util/sync2/atomic2"
type Slice interface {
Type() string
Buffer() []byte
reclaim()
Slice2(beg, end int) Slice
Slice3(beg, end, cap int) Slice
Parent() Slice
}
var maxOffheapBytes atomic2.Int64
func MaxOffheapBytes() int64 {
return maxOffheapBytes.Int64()
}
func SetMaxOffheapBytes(n int64) {
maxOffheapBytes.Set(n)
}
const MinOffheapSlice = 1024 * 16
func MakeSlice(n int) Slice {
if n >= MinOffheapSlice {
if s := newCGoSlice(n, false); s != nil {
return s
}
}
return newGoSlice(n)
}
func MakeOffheapSlice(n int) Slice {
if n >= 0 {
return newCGoSlice(n, true)
}
panic("make slice with negative size")
}
func FreeSlice(s Slice) {
if s != nil {
s.reclaim()
}
}