[agent/codex:gpt-5.3-codex-spark] Read docs/RFC.md fully. Find ONE feature described in the sp... #16
2 changed files with 10 additions and 1 deletions
|
|
@ -42,6 +42,10 @@ func NewBuffer(size int) *Buffer {
|
|||
buffer.pointer = unsafe.Pointer(&buffer.data[0])
|
||||
}
|
||||
|
||||
runtime.SetFinalizer(buffer, func(owned *Buffer) {
|
||||
owned.Free()
|
||||
})
|
||||
|
||||
return buffer
|
||||
}
|
||||
|
||||
|
|
|
|||
7
scope.go
7
scope.go
|
|
@ -6,6 +6,7 @@ package cgo
|
|||
import "C"
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"unsafe"
|
||||
|
|
@ -29,7 +30,11 @@ type Scope struct {
|
|||
// scope := NewScope()
|
||||
// defer scope.FreeAll()
|
||||
func NewScope() *Scope {
|
||||
return &Scope{}
|
||||
scope := &Scope{}
|
||||
runtime.SetFinalizer(scope, func(owned *Scope) {
|
||||
owned.FreeAll()
|
||||
})
|
||||
return scope
|
||||
}
|
||||
|
||||
// Buffer allocates a managed buffer and registers it for scope cleanup.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue