github.com/outcaste-io/ristretto@v0.2.3/contrib/demo/node_jemalloc.go (about)

     1  // +build jemalloc,!allocator
     2  
     3  package main
     4  
     5  import (
     6  	"unsafe"
     7  
     8  	"github.com/outcaste-io/ristretto/z"
     9  )
    10  
    11  func newNode(val int) *node {
    12  	b := z.Calloc(nodeSz, "demo")
    13  	n := (*node)(unsafe.Pointer(&b[0]))
    14  	n.val = val
    15  	return n
    16  }
    17  
    18  func freeNode(n *node) {
    19  	buf := (*[z.MaxArrayLen]byte)(unsafe.Pointer(n))[:nodeSz:nodeSz]
    20  	z.Free(buf)
    21  }