by sapiogram · 2y ago · 0 comments
arena := NewSlabArena(8182, 1) // 8KB
var b *byte = New[byte](arena)
var i *int = New[int](arena)
fmt.Printf("Pointer address: %p\n", b)
fmt.Printf("Pointer address: %p\n", i)
Result: Pointer address: 0x14000198000
Pointer address: 0x14000198001
I'm not a Go language lawyer, but I assume this is just immediate UB. OP, it's fine to publish a library without experience in manual memory management, but maybe put a disclaimer in the README?Maybe? But that seems strange, since they seem to have intended it to be used for http servers making per-request allocations.
Come to think of it, the arena is probably still unsound with just ints, because the underlying allocation is just for a `[]byte`, which I don't think is guaranteed to be aligned to 8 bytes. Might be on most platforms, though.