The memory for param comes from the Mmap, so assigning a member of param directly will cause problems.
func InitNullMap(param *tree.ExternParam, ctx CompilerContext) error {
m := make(map[string][]string)
param.NullMap = m
// write of unpinned Go pointer 0x1400cac1ce0 to non-Go memory 0x10ed44110
// fatal error: unpinned Go pointer stored into non-Go memory
I’ve used runtime.Pinner successfully with other common datatypes, such as structures or strings, but I’ve found that I can’t handle map.
m := make(map[string][]string)
buf := ctx.GetBuffer()
buf.Pin(m)
param.NullMap = m
// what buf is and what buf.Pin do
func New() *Buffer {
b := new(Buffer)
b.pinner = new(runtime.Pinner)
b.pinner.Pin(b)
return b
}
func (b *Buffer) Pin(os ...any) {
for _, o := range os {
b.pinner.Pin(o)
}
}
There are no examples in go/src/runtime/pinner_test.go, and I haven’t found any useful discussions, can anyone help ?