MCPcopy
hub / github.com/CodisLabs/codis / newCGoSlice

Function newCGoSlice

pkg/utils/unsafe2/cgo_slice.go:25–44  ·  view source on GitHub ↗
(n int, force bool)

Source from the content-addressed store, hash-verified

23}
24
25func newCGoSlice(n int, force bool) Slice {
26 after := allocOffheapBytes.Add(int64(n))
27 if !force && after > MaxOffheapBytes() {
28 allocOffheapBytes.Sub(int64(n))
29 return nil
30 }
31 p := cgo_malloc(n)
32 if p == nil {
33 allocOffheapBytes.Sub(int64(n))
34 return nil
35 }
36 s := &cgoSlice{
37 ptr: p,
38 buf: *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
39 Data: uintptr(p), Len: n, Cap: n,
40 })),
41 }
42 runtime.SetFinalizer(s, (*cgoSlice).reclaim)
43 return s
44}
45
46func (s *cgoSlice) Type() string {
47 return "cgo_slice"

Callers 2

MakeSliceFunction · 0.85
MakeOffheapSliceFunction · 0.85

Calls 4

MaxOffheapBytesFunction · 0.85
SubMethod · 0.80
cgo_mallocFunction · 0.70
AddMethod · 0.45

Tested by

no test coverage detected