Przeglądaj źródła

Attempt to free stdout memory

Luna Stadler 4 lat temu
rodzic
commit
a906808ef7
1 zmienionych plików z 4 dodań i 1 usunięć
  1. 4 1
      zig/sdl/hello_sdl.zig

+ 4 - 1
zig/sdl/hello_sdl.zig

64
    var pos: usize = 0;
64
    var pos: usize = 0;
65
    var max_chars = std.math.min(@divTrunc(@intCast(usize, window_width), @intCast(usize, glyph_width)), msg.len);
65
    var max_chars = std.math.min(@divTrunc(@intCast(usize, window_width), @intCast(usize, glyph_width)), msg.len);
66
66
67
    var result: []const u8 = "";
67
    var result: []const u8 = try gpa.alloc(u8, 0);
68
68
69
    const keyboardState = c.SDL_GetKeyboardState(null);
69
    const keyboardState = c.SDL_GetKeyboardState(null);
70
70
115
                                msg[pos] = '_';
115
                                msg[pos] = '_';
116
                            },
116
                            },
117
                            c.SDLK_RETURN => {
117
                            c.SDLK_RETURN => {
118
                                gpa.free(result);
118
                                result = try runCommand(&msg, gpa);
119
                                result = try runCommand(&msg, gpa);
119
                                var i: usize = 0;
120
                                var i: usize = 0;
120
                                while (i < max_chars) : (i += 1) {
121
                                while (i < max_chars) : (i += 1) {
170
171
171
        c.SDL_Delay(16);
172
        c.SDL_Delay(16);
172
    }
173
    }
174
175
    _ = general_purpose_allocator.detectLeaks();
173
}
176
}
174
177
175
fn runCommand(raw_cmd: []const u8, allocator: *std.mem.Allocator) ![]const u8 {
178
fn runCommand(raw_cmd: []const u8, allocator: *std.mem.Allocator) ![]const u8 {