From: Brendan Hansen Date: Wed, 8 Mar 2023 20:38:07 +0000 (-0600) Subject: added: `core.alloc.arena.auto_temp()` X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=bec96483ebd64bda30fb84638e53eb3d801b75a9;p=onyx.git added: `core.alloc.arena.auto_temp()` --- diff --git a/core/alloc/arena.onyx b/core/alloc/arena.onyx index 13e91135..d9ef2a47 100644 --- a/core/alloc/arena.onyx +++ b/core/alloc/arena.onyx @@ -181,3 +181,16 @@ auto :: #match { return 0; } } + +auto_temp :: macro (body: Code) -> i32 { + use core.alloc {arena, heap_allocator} + a := arena.make(heap_allocator, 32 * 1024); + + old_allocator := context.temp_allocator; + context.temp_allocator = arena.make_allocator(&a); + + #unquote body; + + arena.free(&a); + context.temp_allocator = old_allocator; +}