aboutsummaryrefslogtreecommitdiff
path: root/lib/std/heap
AgeCommit message (Collapse)Author
2025-11-15MemoryPool: add unmanaged variants and make them the defaultJustus Klausecker
2025-10-29std: fix compilation errors on WindowsAndrew Kelley
2025-10-28std.heap.debug_allocator outdated doc (#25634)Adrian
Fixed a relatively small outdated doc string, referring to the bucket linked list.
2025-10-18std.Build.Step.Run: many enhancementsmlugg
This is a major refactor to `Step.Run` which adds new functionality, primarily to the execution of Zig tests. * All tests are run, even if a test crashes. This happens through the same mechanism as timeouts where the test processes is repeatedly respawned as needed. * The build status output is more precise. For each unit test, it differentiates pass, skip, fail, crash, and timeout. Memory leaks are reported separately, as they do not indicate a test's "status", but are rather an additional property (a test with leaks may still pass!). * The number of memory leaks is tracked and reported, both per-test and for a whole `Run` step. * Reporting is made clearer when a step is failed solely due to error logs (`std.log.err`) where every unit test passed.
2025-09-30std: rework/remove ucontext_tmlugg
Our usage of `ucontext_t` in the standard library was kind of problematic. We unnecessarily mimiced libc-specific structures, and our `getcontext` implementation was overkill for our use case of stack tracing. This commit introduces a new namespace, `std.debug.cpu_context`, which contains "context" types for various architectures (currently x86, x86_64, ARM, and AARCH64) containing the general-purpose CPU registers; the ones needed in practice for stack unwinding. Each implementation has a function `current` which populates the structure using inline assembly. The structure is user-overrideable, though that should only be necessary if the standard library does not have an implementation for the *architecture*: that is to say, none of this is OS-dependent. Of course, in POSIX signal handlers, we get a `ucontext_t` from the kernel. The function `std.debug.cpu_context.fromPosixSignalContext` converts this to a `std.debug.cpu_context.Native` with a big ol' target switch. This functionality is not exposed from `std.c` or `std.posix`, and neither are `ucontext_t`, `mcontext_t`, or `getcontext`. The rationale is that these types and functions do not conform to a specific ABI, and in fact tend to get updated over time based on CPU features and extensions; in addition, different libcs use different structures which are "partially compatible" with the kernel structure. Overall, it's a mess, but all we need is the kernel context, so we can just define a kernel-compatible structure as long as we don't claim C compatibility by putting it in `std.c` or `std.posix`. This change resulted in a few nice `std.debug` simplifications, but nothing too noteworthy. However, the main benefit of this change is that DWARF unwinding---sometimes necessary for collecting stack traces reliably---now requires far less target-specific integration. Also fix a bug I noticed in `PageAllocator` (I found this due to a bug in my distro's QEMU distribution; thanks, broken QEMU patch!) and I think a couple of minor bugs in `std.debug`. Resolves: #23801 Resolves: #23802
2025-09-30replace usages of old std.debug APIsmlugg
src/crash_handler.zig is still TODO though, i am planning bigger changes there
2025-08-11std.ArrayList: make unmanaged the defaultAndrew Kelley
2025-08-03zig fmt: apply new cast builtin orderJustus Klausecker
2025-07-10Merge pull request #24387 from ziglang/std.log.default_levelAndrew Kelley
std.log: adjust default level for ReleaseSmall to include info + bonus cleanup
2025-07-09std: refactor to use Alignment.ofAndrew Kelley
2025-07-07std.fmt: breaking API changesAndrew Kelley
added adapter to AnyWriter and GenericWriter to help bridge the gap between old and new API make std.testing.expectFmt work at compile-time std.fmt no longer has a dependency on std.unicode. Formatted printing was never properly unicode-aware. Now it no longer pretends to be. Breakage/deprecations: * std.fs.File.reader -> std.fs.File.deprecatedReader * std.fs.File.writer -> std.fs.File.deprecatedWriter * std.io.GenericReader -> std.io.Reader * std.io.GenericWriter -> std.io.Writer * std.io.AnyReader -> std.io.Reader * std.io.AnyWriter -> std.io.Writer * std.fmt.format -> std.fmt.deprecatedFormat * std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape * std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape * std.fmt.fmtSliceHexLower -> {x} * std.fmt.fmtSliceHexUpper -> {X} * std.fmt.fmtIntSizeDec -> {B} * std.fmt.fmtIntSizeBin -> {Bi} * std.fmt.fmtDuration -> {D} * std.fmt.fmtDurationSigned -> {D} * {} -> {f} when there is a format method * format method signature - anytype -> *std.io.Writer - inferred error set -> error{WriteFailed} - options -> (deleted) * std.fmt.Formatted - now takes context type explicitly - no fmt string
2025-06-12x86_64: remove linker references from codegenJacob Young
2025-04-13std: eradicate u29 and embrace std.mem.AlignmentAndrew Kelley
2025-04-03de-genericify SinglyLinkedListAndrew Kelley
by making it always intrusive, we make it a more broadly useful API, and avoid binary bloat.
2025-04-02DebugAllocator: Fix bucket removal logic causing segfault/leak (#23390)Auguste Rame
Make buckets doubly linked
2025-03-25Update the documentation comment in arena_allocator.zig to be more accurategodalming123
Update the documentation comment in arena_allocator.zig to specify that free() is a no-op unless the item is the most recent allocation.
2025-03-04update std.heap.PageAllocator Windows implementation to remove race ↵ziggoon
condition and utilize NtAllocateVirtualMemory / NtFreeVirtualMemory instead of VirtualAlloc and VirtualFree
2025-02-22std.heap.DebugAllocator: default wasm to 64K page sizeAndrew Kelley
including on freestanding
2025-02-17std.Target: Remove functions that just wrap component functions.Alex Rønne Petersen
Functions like isMinGW() and isGnuLibC() have a good reason to exist: They look at multiple components of the target. But functions like isWasm(), isDarwin(), isGnu(), etc only exist to save 4-8 characters. I don't think this is a good enough reason to keep them, especially given that: * It's not immediately obvious to a reader whether target.isDarwin() means the same thing as target.os.tag.isDarwin() precisely because isMinGW() and similar functions *do* look at multiple components. * It's not clear where we would draw the line. The logical conclusion before this commit would be to also wrap Arch.isX86(), Os.Tag.isSolarish(), Abi.isOpenHarmony(), etc... this obviously quickly gets out of hand. * It's nice to just have a single correct way of doing something.
2025-02-17Fix build failure in sbrk allocator, caused by #20511schtvn
2025-02-10std.ArrayList: popOrNull() -> pop() [v2] (#22720)Meghan Denny
2025-02-08std.heap.SmpAllocator: back to simple freeAndrew Kelley
In practice this is fine because eventually alloc wins the race and grabs that massive freelist.
2025-02-08std.heap.SmpAllocator: alternate freelist accountingAndrew Kelley
Freelist length accounting in alloc had a negative impact, especially with the integer type bumped up to u16, so I changed the system to be based on counting slabs rather than total allocations.
2025-02-08std.heap.SmpAllocator; fix freelist accountingAndrew Kelley
2025-02-07std.heap.SmpAllocator: rotate on free sometimesAndrew Kelley
* slab length reduced to 64K * track freelist length with u8s * on free(), rotate if freelist length exceeds max_freelist_len Prevents memory leakage in the scenario where one thread only allocates and another thread only frees.
2025-02-07std.heap.SmpAllocator: fix detection of slab endAndrew Kelley
2025-02-07std.heap.SmpAllocator: fix getCpuCount logicAndrew Kelley
it was always returning max_cpu_count
2025-02-07std.heap.SmpAllocator: simplify by putting freelist node at startAndrew Kelley
2025-02-07std.heap.SmpAllocator: fix using wrong size class indicesAndrew Kelley
2025-02-07std.heap.SmpAllocator: eliminate the global mutexAndrew Kelley
2025-02-07std.heap.SmpAllocator: implement searching on allocAndrew Kelley
rotate a couple times before resorting to mapping more memory.
2025-02-07std.heap.SmpAllocator: 256K slab_lenAndrew Kelley
and no need for special handling of wasi and windows since we don't ask for anything more than page-aligned.
2025-02-07std.heap: test smp_allocatorAndrew Kelley
2025-02-07add std.heap.SmpAllocatorAndrew Kelley
An allocator intended to be used in -OReleaseFast mode when multi-threading is enabled.
2025-02-06std.heap.SbrkAllocator: fix typoAndrew Kelley
2025-02-06std.heap.DebugAllocator: update unit tests for new implAndrew Kelley
No longer need this windows-specific behavior.
2025-02-06std.heap.DebugAllocator: make page size configurableAndrew Kelley
2025-02-06std.heap: rename GeneralPurposeAllocator to DebugAllocatorAndrew Kelley
2025-02-06std.heap.GeneralPurposeAllocator: fix UAF in resizeLargeAndrew Kelley
There was an ensureUnusedCapacity() call that invalidated a looked-up hash table entry. Move it earlier.
2025-02-06std.heap.GeneralPurposeAllocator: fix slot_counts calculationAndrew Kelley
In larger small buckets, the comptime logic that computed slot count did not verify that the number it produced was valid. Now it verifies it, which made this bug into a compile error. Then I fixed the bug by introducing a "minimum slots per bucket" declaration.
2025-02-06std: fix compilation under -lcAndrew Kelley
2025-02-06std.heap.GeneralPurposeAllocator: usize for used_bitsAndrew Kelley
improves leak checking performance.
2025-02-06std.heap.GeneralPurposeAllocator: use for loops in leak checkAndrew Kelley
2025-02-06std.heap.GeneralPurposeAllocator: reduce page size to 512KAndrew Kelley
and fix compilation on 32-bit targets
2025-02-06std.heap.WasmAllocator: update to new Allocator APIAndrew Kelley
2025-02-06std.heap.GeneralPurposeAllocator: implement resize and remapAndrew Kelley
2025-02-06std.heap.GeneralPurposeAllocator: check canary in freeAndrew Kelley
2025-02-06std.heap.GeneralPurposeAllocator: inline small allocation metadataAndrew Kelley
Put the small allocation metadata directly into the (large) pages allocated.
2025-02-06std.heap.ThreadSafeAllocator: update to new Allocator APIAndrew Kelley
2025-02-06std.mem.Allocator: keep the undefined memsetAndrew Kelley
Reversal on the decision: the Allocator interface is the correct place for the memset to undefined because it allows Allocator implementations to bypass the interface and use a backing allocator directly, skipping the performance penalty of memsetting the entire allocation, which may be very large, as well as having valuable zeroes on them. closes #4298