mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
use c allocator in release modes if available
This commit is contained in:
23
src/main.zig
23
src/main.zig
@ -1,3 +1,4 @@
|
|||||||
|
const builtin = @import("builtin");
|
||||||
const options = @import("build_options");
|
const options = @import("build_options");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const glfw = @import("glfw");
|
const glfw = @import("glfw");
|
||||||
@ -8,9 +9,25 @@ const tracy = @import("tracy/tracy.zig");
|
|||||||
const Config = @import("config.zig").Config;
|
const Config = @import("config.zig").Config;
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
|
const gpa = gpa: {
|
||||||
const gpa = general_purpose_allocator.allocator();
|
// Use the libc allocator if it is available beacuse it is WAY
|
||||||
defer _ = general_purpose_allocator.deinit();
|
// faster than GPA. We only do this in release modes so that we
|
||||||
|
// can get easy memory leak detection in debug modes.
|
||||||
|
if (builtin.link_libc) {
|
||||||
|
switch (builtin.mode) {
|
||||||
|
.ReleaseSafe, .ReleaseFast => break :gpa std.heap.c_allocator,
|
||||||
|
else => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We don't ever deinit our GPA because the process cleanup will
|
||||||
|
// clean it up. This defer isn't in the right location anyways because
|
||||||
|
// it'll deinit on return from blk.
|
||||||
|
// defer _ = general_purpose_allocator.deinit();
|
||||||
|
|
||||||
|
var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
|
||||||
|
break :gpa general_purpose_allocator.allocator();
|
||||||
|
};
|
||||||
|
|
||||||
// If we're tracing, then wrap memory so we can trace allocations
|
// If we're tracing, then wrap memory so we can trace allocations
|
||||||
const alloc = if (!tracy.enabled) gpa else tracy.allocator(gpa, null).allocator();
|
const alloc = if (!tracy.enabled) gpa else tracy.allocator(gpa, null).allocator();
|
||||||
|
Reference in New Issue
Block a user