Skip to content

v1.2.0

Choose a tag to compare

@pboyd pboyd released this 20 Feb 13:29
· 2 commits to main since this release

VirtBackend

v1.2.0 adds VirtBackend, a fixed-capacity backend that reserves a contiguous virtual address range at startup and commits physical memory on demand.

backend, err := malloc.VirtBackend(64 << 20) // reserve 64 MiB
if err != nil {
    log.Fatal(err)
}

Each Grow call extends the committed region in place, so all allocations share the same base address. This makes VirtBackend a good fit for arenas where you know the maximum size upfront and need pointers to remain valid after the arena grows. When committed memory reaches the reserved capacity, Grow returns ErrOutOfMemory.

On Unix, VirtBackend reserves address space with PROT_NONE and commits pages via mprotect. On Windows, it uses MEM_RESERVE followed by MEM_COMMIT. VirtBackend implements ProtectedArenaBackend.

MmapBackend options (breaking change)

MmapBackend now accepts variadic BackendOpt options instead of positional prot and flags integers.

Before:

backend := malloc.MmapBackend(syscall.PROT_EXEC, 0)

After:

backend := malloc.MmapBackend(malloc.MmapProt(syscall.PROT_EXEC))

A new MmapAddr option requests a preferred mapping address from the kernel. These same options work with VirtBackend.

Bug fixes

  • Fixed exec protection flag for MmapBackend on Windows.