aboutsummaryrefslogtreecommitdiff
path: root/lib/std/heap/arena_allocator.zig
AgeCommit message (Collapse)Author
2025-07-09std: refactor to use Alignment.ofAndrew Kelley
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-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-02-06std.mem.Allocator: introduce `remap` function to the interfaceAndrew Kelley
This one changes the size of an allocation, allowing it to be relocated. However, the implementation will still return `null` if it would be equivalent to new = alloc memcpy(new, old) free(old) Mainly this prepares for taking advantage of `mremap` which I thought would be a bigger deal but apparently is only available on Linux. Still, we should use it on Linux.
2024-07-23add std.testing.random_seedAndrew Kelley
closes #17609
2024-02-26Remove redundant test name prefixes now that test names are fully qualifiedRyan Liptak
Follow up to #19079, which made test names fully qualified. This fixes tests that now-redundant information in their test names. For example here's a fully qualified test name before the changes in this commit: "priority_queue.test.std.PriorityQueue: shrinkAndFree" and the same test's name after the changes in this commit: "priority_queue.test.shrinkAndFree"
2024-02-08Replace std.rand references with std.Randome4m2
2023-11-19lib: correct unnecessary uses of 'var'mlugg
2023-10-15std.heap.ArenaAllocator: fix doc comment typoJohan Jansson
Fixes #17537
2023-06-24all: migrate code to new cast builtin syntaxmlugg
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
2023-06-19all: zig fmt and rename "@XToY" to "@YFromX"Eric Joldasov
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-17mem: rename align*Generic to mem.align*Motiejus Jakštys
Anecdote 1: The generic version is way more popular than the non-generic one in Zig codebase: git grep -w alignForward | wc -l 56 git grep -w alignForwardGeneric | wc -l 149 git grep -w alignBackward | wc -l 6 git grep -w alignBackwardGeneric | wc -l 15 Anecdote 2: In my project (turbonss) that does much arithmetic and alignment I exclusively use the Generic functions. Anecdote 3: we used only the Generic versions in the Macho Man's linker workshop.
2023-06-16migration: std.math.{min, min3, max, max3} -> `@min` & `@max`r00ster91
2023-06-13arena_allocator/reset: avoid zero-capacity allocationsErik Arvstedt
1. When the arena is already empty, resetting with `retain_capacity` no longer results in allocating a buffer with zero capacity. This behavior was previously intended by the `(current_capacity == 0)` check, but wasn't correctly implemented. 2. Resetting with `.{ .retain_with_limit = 0 }` is now equivalent to `free_all` and a new buffer with zero capacity is no longer created. This is a useful side-effect of the above fixes.
2023-06-13arena_allocator/reset: fix use after freeErik Arvstedt
Previously, when the last buffer in `buffer_list` was retained after deleting all other buffers, `buffer_list` wasn't updated and pointed to a deleted buffer.
2023-06-13arena_allocator/reset: fix buffer overrunErik Arvstedt
Previously, the buffer reserved with `retain_with_limit` was missing space for the `BufNode`. When the user-provided a limit that was smaller than `@sizeOf(BufNode)`, `reset` would store a new `BufNode` in an allocation smaller than `BufNode`, leading to a buffer overrun.
2023-04-30std: fix a bunch of typosLinus Groh
The majority of these are in comments, some in doc comments which might affect the generated documentation, and a few in parameter names - nothing that should be breaking, however.
2023-04-05std: fix memory bugsJacob Young
This fixes logged errors during CI based on the new GPA checks.
2023-01-03Implements std.ArenaAllocator.reset() (#12590)Felix Queißner
Co-authored-by: Felix "xq" Queißner <xq@random-projects.net>
2022-11-30std.ArrayList: fix shrinkAndFreeAndrew Kelley
Fixes a regression introduced in e35f297aeb993ec956ae80379ddf7f86069e109b. Now there is test coverage for ArrayList.shrinkAndFree in the case when resizing fails.
2022-11-29std.mem.Allocator: allow shrink to failAndrew Kelley
closes #13535
2021-11-30allocgate: change resize to return optional instead of errorLee Cannon
2021-11-30allocgate: split free out from resizeLee Cannon
2021-11-30allocgate: utilize a *const vtable fieldLee Cannon
2021-11-30allocgate: renamed getAllocator function to allocatorLee Cannon
2021-11-30allocgate: std Allocator interface refactorLee Cannon
2021-08-24remove redundant license headers from zig standard libraryAndrew Kelley
We already have a LICENSE file that covers the Zig Standard Library. We no longer need to remind everyone that the license is MIT in every single file. Previously this was introduced to clarify the situation for a fork of Zig that made Zig's LICENSE file harder to find, and replaced it with their own license that required annual payments to their company. However that fork now appears to be dead. So there is no need to reinforce the copyright notice in every single file.
2021-06-21fix code broken from previous commitJacob G-W
2020-12-31Year++Frank Denis
2020-09-25std: ArenaAllocator tries to resize before allocatingLemonBoy
Closes #5116
2020-09-08Add resize for arena allocatorMark Barbone
2020-08-20add license header to all std lib filesAndrew Kelley
add SPDX license identifier copyright ownership is zig contributors
2020-08-08std.mem.Allocator: add return_address to the interfaceAndrew Kelley
The high level Allocator interface API functions will now do a `@returnAddress()` so that stack traces captured by allocator implementations have a return address that does not include the Allocator overhead functions. This makes `4` a more reasonable default for how many stack frames to capture.
2020-08-07std: introduce GeneralPurposeAllocatorAndrew Kelley
`std.GeneralPurposeAllocator` is now available. It is a function that takes a configuration struct (with default field values) and returns an allocator. There is a detailed description of this allocator in the doc comments at the top of the new file. The main feature of this allocator is that it is *safe*. It prevents double-free, use-after-free, and detects leaks. Some deprecation compile errors are removed. The Allocator interface gains `old_align` as a new parameter to `resizeFn`. This is useful to quickly look up allocations. `std.heap.page_allocator` is improved to use mmap address hints to avoid obtaining the same virtual address pages when unmapping and mapping pages. The new general purpose allocator uses the page allocator as its backing allocator by default. `std.testing.allocator` is replaced with usage of this new allocator, which does leak checking, and so the LeakCheckAllocator is retired. stage1 is improved so that the `@typeInfo` of a pointer has a lazy value for the alignment of the child type, to avoid false dependency loops when dealing with pointers to async function frames. The `std.mem.Allocator` interface is refactored to be in its own file. `std.Mutex` now exposes the dummy mutex with `std.Mutex.Dummy`. This allocator is great for debug mode, however it needs some work to have better performance in release modes. The next step will be setting up a series of tests in ziglang/gotta-go-fast and then making improvements to the implementation.
2020-06-29ArenaAllocator: use full capacityJonathan Marler
2020-06-29Revert "arena_allocator: refactor and use full capacity"Jonathan Marler
This reverts commit e120b07a524f1accd4975f5206018c61c4be9345.
2020-06-28arena_allocator: refactor and use full capacityJonathan Marler
2020-06-27new allocator interface after Andrew Kelley reviewJonathan Marler
2020-06-26new allocator interfaceJonathan Marler
2020-05-20small bump to ArenaAllocator minimum alloc sizeAndrew Kelley
self-hosted parser benchmark: throughput: 69.4 MiB/s => 72.2 MiB/s
2020-05-20arena allocator: smaller minimum allocation sizeAndrew Kelley
2020-05-10rework self-hosted compiler for incremental buildsAndrew Kelley
* introduce std.ArrayListUnmanaged for when you have the allocator stored elsewhere * move std.heap.ArenaAllocator implementation to its own file. extract the main state into std.heap.ArenaAllocator.State, which can be stored as an alternative to storing the entire ArenaAllocator, saving 24 bytes per ArenaAllocator on 64 bit targets. * std.LinkedList.Node pointer field now defaults to being null initialized. * Rework self-hosted compiler Package API * Delete almost all the bitrotted self-hosted compiler code. The only bit rotted code left is in main.zig and compilation.zig * Add call instruction to ZIR * self-hosted compiler ir API and link API are reworked to support a long-running compiler that incrementally updates declarations * Introduce the concept of scopes to ZIR semantic analysis * ZIR text format supports referencing named decls that are declared later in the file * Figure out how memory management works for the long-running compiler and incremental compilation. The main roots are top level declarations. There is a table of decls. The key is a cryptographic hash of the fully qualified decl name. Each decl has an arena allocator where all of the memory related to that decl is stored. Each code block has its own arena allocator for the lifetime of the block. Values that want to survive when going out of scope in a block must get copied into the outer block. Finally, values must get copied into the Decl arena to be long-lived. * Delete the unused MemoryCell struct. Instead, comptime pointers are based on references to Decl structs. * Figure out how caching works. Each Decl will store a set of other Decls which must be recompiled when it changes. This branch is still work-in-progress; this commit breaks the build.