25 ms·
Although it doesn't have the same level of compile-time guarantees, there are runtime checks to ensure memory safety if you use Debug or ReleaseSafe. You can do
by jonathrg 2y ago
Although it doesn't have the same level of compile-time guarantees, there are runtime checks to ensure memory safety if you use Debug or ReleaseSafe. You can do your development and testing in the default Debug mode and only use ReleaseFast or ReleaseSmall once you need the extra optimization and are confident in your test coverage.
- DanielHB 2y agoJust wondering, if you don't care about that much about the performance for your application, is it okay to use the runtime checks compilation in production? Like say I have a really weird issue I can't seem to find locally, can I switch my production server to this different compilation mode temporarily to get better logs? Can I run my development environment with it on all the time?
- laserbeam 2y agoCertain classes of programs should be built as ReleaseSafe rather than ReleaseFast to keep many of the runtime checks. It's perfectly reasonable to write a database and build as ReleaseSafe, but also make a game and build it as ReleaseFast.
- sciolistse 2y agoYou can definitely use ReleaseSafe, you can also switch modes during compilation. so you can call '@setRuntimeSafety(false)' at the start of a scope to disable runtime safety for performance critical sections.
- DanielHB 2y agothis is an amazing feature
- jonathrg 2y agoSure, an application built in Debug mode with a compiled language is going to be much faster than if you implemented it in an interpreted language. Given how much of the world runs on Python, PHP and Javascript, your zig application in debug mode is probably going to run just fine.
- bmacho 2y ago> Although it doesn't have the same level of compile-time guarantees, there are runtime checks to ensure memory safety if you use Debug or ReleaseSafe. it is not very good, as const std = @import("std"); const print = std.debug.print; fn foo() fn() *u32 { const T = struct { fn bar() *u32 { var x: u32 = 123; return &x; } }; return T.bar; } pub fn main() void { print("Resultt: {}", .{foo()().*}); } outputs 123 in debug[0] and 0 in ReleaseSafe[1] instead of giving a Runtime Error. [0] https://zig.godbolt.org/z/ezTr3zP6a https://zig.godbolt.org/z/ezTr3zP6a [1] https://zig.godbolt.org/z/3ExeveT69 https://zig.godbolt.org/z/3ExeveT69