3 ms·
I'm not close to Zig development, but in addition to the GeneralPurposeAllocator work that a comment already links to, there is other ongoing stuff in that spac
by azakai 5y ago
I'm not close to Zig development, but in addition to the GeneralPurposeAllocator work that a comment already links to, there is other ongoing stuff in that space, like an allocator in 64-bit that does not reuse pages (and instead keeps using new addresses in the "infinite" 64-bit space).
There are also known techniques like Type-After-Type that can avoid use-after free in C and C++ [0]. And also advances in hardware like ARM MTE [1]. Those things - and GPA, and not reusing 64-bit pages - have various tradeoffs in terms of overhead, but Zig is a developing language that has a chance to explore possibilities that C and C++ can't. So this is an interesting area to follow.
[0] https://dl.acm.org/doi/10.1145/3274694.3274705 https://dl.acm.org/doi/10.1145/3274694.3274705
[1] https://security.googleblog.com/2019/08/adopting-arm-memory-tagging-extension.html https://security.googleblog.com/2019/08/adopting-arm-memory-...
- kobebrookskC3 5y agowhat does zig offer over c/c++ with sanitizers?
- dnautics 5y agoSanity. Seriously. You get these tests for free with zig, no extra tooling, if you use testing allocator in your tests. This also is a carrot to get you to write tests. Hell, I even mocked libc's malloc/calloc/free to make sure that my code doesn't leak memory: https://github.com/ityonemo/Primes/blob/ee81d05e80d68854ab1139b27e5607b65997fd80/PrimeZig/solution_3/src/alloc.zig#L175 https://github.com/ityonemo/Primes/blob/ee81d05e80d68854ab11...
- pjmlp 5y agoWhat sanity when the developer is still responsible for tracking memory manually by themselves? > It is the Zig programmer's responsibility to ensure that a pointer is not accessed when the memory pointed to is no longer available. https://ziglang.org/documentation/0.8.1/#Memory https://ziglang.org/documentation/0.8.1/#Memory Mocking malloc you say? https://docs.microsoft.com/en-us/visualstudio/debugger/crt-debug-heap-details?view=vs-2019 https://docs.microsoft.com/en-us/visualstudio/debugger/crt-d... It exists at very least since Visual C++ 5.0, and Borland had similar tooling since their first Win16 compilers.
- dnautics 5y agoRust does not free you from having to track memory, for large classes of important data structures. And, if you want to implement smart pointers for your app in zig, it is easy. Yes, your examples are two proprietary, nonstandard techniques. Or alternatively using a third-class toolset (jemalloc toolkit e.g ). Sanity is having a single, anointed way to do it in the stdlib.