What about temporary allocators ? #86
serge-hulne
started this conversation in
General
Replies: 1 comment 2 replies
|
So uses arenas, and passes the allocator as a parameter instead of using var buf [4096]byte
arena := mem.NewArena(buf[:])
for _, item := range items {
process(&arena, item) // allocates without individual .Free calls
arena.Reset() // reclaims everything at once
}Reset is a regular method call, not a Unlike C3, you can choose where the underlying buffer is allocated — either on the stack (like in the example above) or on the heap: buf := mem.AllocSlice[byte](mem.System, 4096, 4096)
defer mem.FreeSlice(mem.System, buf)
arena := mem.NewArena(buf)The downside is that you have to pass |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Exemple from C3
All reactions