updated day 20 to use a ring allocator
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 22 Dec 2020 16:18:09 +0000 (10:18 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 22 Dec 2020 16:18:09 +0000 (10:18 -0600)
day20.onyx

index 547c0bc66b53d37065f8df6c52e017913dcb1f1b..6cbc048c0ab39fae8ef09c30f29d397712e51b4f 100644 (file)
@@ -263,8 +263,12 @@ main :: proc (args: [] cstr) {
        tile_data := calloc(200 * sizeof TileData);
        defer cfree(tile_data);
        
-       tile_data_arena := alloc.arena.make(tile_data, 200 * sizeof TileData);
-       tile_allocator  := alloc.arena.make_allocator(^tile_data_arena);
+    // This ring allocator could technically overflow and start
+    // allocating memory that isn't technically free, but there
+    // should be more than enough space in the allocator to not
+    // run into that problem... Hopefully.
+       tile_data_ring := alloc.ring.make(tile_data, 200 * sizeof TileData);
+       tile_allocator := alloc.ring.make_allocator(^tile_data_ring);
 
        while !reader.empty(^file) {
                reader.read_word(^file); // 'Tile '