zig/lib
Matthew Lugg dcc5e0e10e
std.heap: rework c_allocator
The main goal here was to avoid allocating padding and header space if
`malloc` already guarantees the alignment we need via `max_align_t`.
Previously, the compiler was using `std.heap.raw_c_allocator` as its GPA
in some cases depending on `std.c.max_align_t`, but that's pretty
fragile (it meant we had to encode our alignment requirements into
`src/main.zig`!). Perhaps more importantly, that solution is
unnecessarily restrictive: since Zig's `Allocator` API passes the
`Alignment` not only to `alloc`, but also to `free` etc, we are able to
use a different strategy depending on its value. So `c_allocator` can
simply compare the requested align to `Alignment.of(std.c.max_align_t)`,
and use a raw `malloc` call (no header needed!) if it will guarantee a
suitable alignment (which, in practice, will be true the vast majority
of the time).

So in short, this makes `std.heap.c_allocator` more memory efficient,
and probably removes any incentive to use `std.heap.raw_c_allocator`.

I also refactored the `c_allocator` implementation while doing this,
just to neaten things up a little.
2025-12-05 10:19:26 +00:00
..
build-web all: replace all @Type usages 2025-11-22 22:42:38 +00:00
c compiler-rt: move strlen from libzigc to here 2025-08-30 06:36:41 +02:00
compiler Merge pull request #26037 from ziglang/build-runner-std.Io 2025-11-25 02:49:37 -08:00
compiler_rt all: replace all @Type usages 2025-11-22 22:42:38 +00:00
docs all: replace all @Type usages 2025-11-22 22:42:38 +00:00
include remove all IBM AIX and z/OS support 2025-10-29 14:25:51 +01:00
init fix: fix typo in comment by removing repeated 'business' word 2025-08-24 23:00:17 +02:00
libc libc: rename any-macos-any to any-darwin-any 2025-11-14 19:19:00 +01:00
libcxx libcxx: use compiler's _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION when set 2025-11-14 02:02:59 +01:00
libcxxabi remove all IBM AIX and z/OS support 2025-10-29 14:25:51 +01:00
libtsan remove all IBM AIX and z/OS support 2025-10-29 14:25:51 +01:00
libunwind remove all IBM AIX and z/OS support 2025-10-29 14:25:51 +01:00
std std.heap: rework c_allocator 2025-12-05 10:19:26 +00:00
c.zig libc: use zig isnan and derivates for mingw 2025-08-27 03:58:32 +02:00
compiler_rt.zig compiler-rt: remove dead code 2025-11-12 16:00:16 +00:00
fuzzer.zig all: replace all @Type usages 2025-11-22 22:42:38 +00:00
ubsan_rt.zig Coff: implement threadlocal variables 2025-10-10 22:47:47 -07:00
zig.h zig.h: drop dependency on deleted compiler_rt functions 2025-11-12 16:00:16 +00:00