File: node_allocator.go

package info (click to toggle)
golang-github-dgraph-io-ristretto 2.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,004 kB
  • sloc: ansic: 78; asm: 37; makefile: 15
file content (29 lines) | stat: -rw-r--r-- 589 bytes parent folder | download | duplicates (2)
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
//go:build jemalloc && allocator
// +build jemalloc,allocator

package main

import (
	"unsafe"

	"github.com/dgraph-io/ristretto/v2/z"
)

// Defined in node.go.
func init() {
	alloc = z.NewAllocator(10<<20, "demo")
}

func newNode(val int) *node {
	// b := alloc.Allocate(nodeSz)
	b := alloc.AllocateAligned(nodeSz)
	n := (*node)(unsafe.Pointer(&b[0]))
	n.val = val
	alloc.Allocate(1) // Extra allocate just to demonstrate AllocateAligned is working as expected.
	return n
}

func freeNode(n *node) {
	// buf := (*[z.MaxArrayLen]byte)(unsafe.Pointer(n))[:nodeSz:nodeSz]
	// z.Free(buf)
}