diff options
author | Tom Barrett <tom@tombarrett.xyz> | 2021-07-02 17:36:23 +0200 |
---|---|---|
committer | Tom Barrett <tom@tombarrett.xyz> | 2021-07-02 17:36:23 +0200 |
commit | b71d60ad473cf4771dc845c0ce0096bfc7ce8d6d (patch) | |
tree | 039232d79096e87a953857a2a4f0942c37996e5e /src/matrix.zig | |
parent | 92ed513b57e4c4ccf3a413cad763278e3a8372f7 (diff) |
now i properly use dynamic memory, athough its very inefficient
Diffstat (limited to 'src/matrix.zig')
-rw-r--r-- | src/matrix.zig | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/matrix.zig b/src/matrix.zig index eaf9685..e566bc4 100644 --- a/src/matrix.zig +++ b/src/matrix.zig @@ -1,5 +1,6 @@ const std = @import("std"); const ArrayList = std.ArrayList; +const ArenaAllocator = std.heap.ArenaAllocator; const matrix = struct { h: usize, @@ -7,11 +8,11 @@ const matrix = struct { x: ArrayList(f32), }; -pub fn new(h: usize, w: usize, x: []f32) matrix { +pub fn new(arena: *ArenaAllocator, h: usize, w: usize, x: []f32) matrix { var m = matrix{ .h = h, .w = w, - .x = ArrayList(f32).init(std.heap.page_allocator), + .x = ArrayList(f32).init(&arena.allocator), }; var i: usize = 0; @@ -37,8 +38,8 @@ pub fn dot(a: []f32, b: []f32, len: usize, step: usize) f32 { return x; } -pub fn multiply(a: matrix, b: matrix) matrix { - var x = ArrayList(f32).init(std.heap.page_allocator); +pub fn multiply(arena: *ArenaAllocator, a: matrix, b: matrix) matrix { + var x = ArrayList(f32).init(&arena.allocator); var i: usize = 0; var k: usize = 0; @@ -50,5 +51,5 @@ pub fn multiply(a: matrix, b: matrix) matrix { k += a.w; } - return new(a.h, b.w, x.items); + return new(arena, a.h, b.w, x.items); } |