VirtBackend: Addr and Release (breaking change)
VirtBackend now returns *VirtReservationBackend instead of ArenaBackend, exposing two new methods to callers.
Addr() returns the base address of the reserved region. Use it to verify alignment or placement requirements before committing to the arena:
backend, err := malloc.VirtBackend(64 << 20)
if err != nil {
log.Fatal(err)
}
if backend.Addr() % alignment != 0 {
backend.Release()
log.Fatal("unsuitable address")
}
arena := malloc.NewArena(malloc.Backend(backend))Release() frees the entire reservation. Call it when the address returned by Addr is unsuitable, or to free the backend's memory independently of the arena.
Migration
If you stored the result of VirtBackend as an ArenaBackend interface, update the declaration to the concrete type:
// Before
var backend malloc.ArenaBackend
backend, err = malloc.VirtBackend(size)
// After
backend, err := malloc.VirtBackend(size)