From 97062d1e57bcf14f07d4fda95cf4b993880471b2 Mon Sep 17 00:00:00 2001 From: Daniel Gavin Date: Tue, 26 Jul 2022 23:39:50 +0200 Subject: Switching to virtual arena instead of ring buffer --- src/main.odin | 6 +++++- src/server/requests.odin | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main.odin b/src/main.odin index 6ef4778..73eecc2 100644 --- a/src/main.odin +++ b/src/main.odin @@ -11,6 +11,7 @@ import "core:thread" import "core:encoding/json" import "core:reflect" import "core:sync" +import "core:mem/virtual" import "core:intrinsics" @@ -99,7 +100,10 @@ main :: proc() { context.logger = log.create_file_logger(fh, log.Level.Info) */ - init_global_temporary_allocator(mem.Megabyte*10) + + growing_arena: virtual.Growing_Arena + + context.temp_allocator = virtual.growing_arena_allocator(&growing_arena) run(&reader, &writer) } diff --git a/src/server/requests.odin b/src/server/requests.odin index 47f0d74..b7774d5 100644 --- a/src/server/requests.odin +++ b/src/server/requests.odin @@ -271,7 +271,8 @@ notification_map: map [string] bool = { } consume_requests :: proc (config: ^common.Config, writer: ^Writer) -> bool { - temp_requests := make([dynamic]Request, 0, context.temp_allocator) + temp_requests := make([dynamic]Request, 0, context.allocator) + defer delete(temp_requests) sync.mutex_lock(&requests_mutex) @@ -301,6 +302,7 @@ consume_requests :: proc (config: ^common.Config, writer: ^Writer) -> bool { request := temp_requests[request_index] call(request.value, request.id, writer, config) json.destroy_value(request.value) + free_all(context.temp_allocator) } sync.mutex_lock(&requests_mutex) -- cgit v1.2.3