func (s *AllocatorSession) Realloc(p unsafe.Pointer, size uintptr) unsafe.Pointer {
	p1 := s.mem.Realloc(p, size)
	if p != p1 {
		s.ptrs[p1] = struct{}{}
		delete(s.ptrs, p)
	}
	return p1
}
Realloc implements Allocator.
package common
import "C"
import (
	"reflect"
	"unsafe"
)
type Allocator interface {
	Malloc(size uintptr) unsafe.Pointer
	Free(p unsafe.Pointer)
	Realloc(p unsafe.Pointer, size uintptr) unsafe.Pointer
}
type AllocatorSession struct {
	mem  Allocator
	ptrs map[unsafe.Pointer]struct{}
}
func rootAlloc(mem Allocator) Allocator {
	for {
		if s, ok := mem.(*AllocatorSession); ok {
			mem = s.mem
		} else {
			return mem
		}
	}
}
func NewAllocatorSession(mem Allocator) *AllocatorSession {
	return &AllocatorSession{rootAlloc(mem), make(map[unsafe.Pointer]struct{})}
}
func (s *AllocatorSession) Malloc(size uintptr) unsafe.Pointer {
	p := s.mem.Malloc(size)
	s.ptrs[p] = struct{}{}
	return p
}
func (s *AllocatorSession) Free(p unsafe.Pointer) {
	s.mem.Free(p)
	delete(s.ptrs, p)
}