aboutsummaryrefslogtreecommitdiff
path: root/lib/std/mem
AgeCommit message (Collapse)Author
2025-10-22std.mem.Allocator: fix resize doc commentJustus Klausecker
2025-09-03Add allocator that always failswhatisaphone
2025-08-24lib: Reword documentation for realloc to clarify size87
"byte size" is confusing. Clarify we mean number of items.
2025-07-09std: refactor to use Alignment.ofAndrew Kelley
2025-04-13std: eradicate u29 and embrace std.mem.AlignmentAndrew Kelley
2025-03-26Allocator.create: properly handle alignment for zero-sized types (#21864)Kendall Condon
2025-03-25Merge pull request #23220 from samy-00007/bytesAsSlice-fixAlex Rønne Petersen
Minor fix for `Allocator.remap` and `mem.bytesAsSlice` for zero-sized types
2025-03-24fix: Allocator.remap now handles zero-bytes sized typessamy007
2025-03-11std.mem.Allocator.remap: fix incorrect doc comment (part 2)mlugg
2025-03-11std.mem.Allocator.remap: fix incorrect doc commentmlugg
Resolves: #23194
2025-02-06std.mem.Allocator.VTable: improve doc comment wordingAndrew 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
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.
2025-02-06GeneralPurposeAllocator: minimal fixAndrew Kelley
This keeps the implementation matching master branch, however, introduces a compile error that applications can work around by explicitly setting page_size_max and page_size_min to match their computer's settings, in the case that those values are not already equal. I plan to rework this allocator in a follow-up enhancement with the goal of reducing total active memory mappings.
2025-02-06adjust runtime page size APIsAndrew Kelley
* fix merge conflicts * rename the declarations * reword documentation * extract FixedBufferAllocator to separate file * take advantage of locals * remove the assertion about max alignment in Allocator API, leaving it Allocator implementation defined * fix non-inline function call in start logic The GeneralPurposeAllocator implementation is totally broken because it uses global state but I didn't address that in this commit.
2025-02-06runtime page size detectionArchbirdplus
heap.zig: define new default page sizes heap.zig: add min/max_page_size and their options lib/std/c: add miscellaneous declarations heap.zig: add pageSize() and its options switch to new page sizes, especially in GPA/stdlib mem.zig: remove page_size
2025-02-03Allocator/Random: document that comparing `ptr` may result in illegal behaviorRyan Liptak
See #21756 and #17704
2025-01-22std.mem.Allocator: remove redundant checkmlugg
This check doesn't make sense with the modern Allocator API; it's left over from when realloc could change alignment. It's statically known (but not comptime-known) to be true always. This check was one of the things blocking Allocator from being used at comptime (related: #1291).
2025-01-16all: update to `std.builtin.Type.{Pointer,Array,StructField}` field renamesmlugg
2025-01-16all: update to `std.builtin.Type.Pointer.Size` field renamesmlugg
This was done by regex substitution with `sed`. I then manually went over the entire diff and fixed any incorrect changes. This diff also changes a lot of `callconv(.C)` to `callconv(.c)`, since my regex happened to also trigger here. I opted to leave these changes in, since they *are* a correct migration, even if they're not the one I was trying to do!
2024-11-24Allocator.free: document zero-length behaviorIlia Choly
It wasn't immediately clear from the implementation whether passing zero-length memory to free() was undefined behavior or intentionally supported. Since ArrayList and other core data structures rely on this behavior working correctly, this should be explicitly documented as part of the public API contract.
2024-08-28std: update `std.builtin.Type` fields to follow naming conventionsmlugg
The compiler actually doesn't need any functional changes for this: Sema does reification based on the tag indices of `std.builtin.Type` already! So, no zig1.wasm update is necessary. This change is necessary to disallow name clashes between fields and decls on a type, which is a prerequisite of #9938.
2023-09-07mem: explicit dupe and dupeZ error on AllocatorPascal S. de Kloe
2023-07-25add error when passing a non-single-item pointer to allocator.destroyxdBronch
2023-07-06Optimize Allocator functions to create less duplicate code for similar types ↵IntegratedQuantum
(#16332) * Move functionality from generic functions that doesn't depend on the type into a function that only depends on comptime alignment. This reduces comptime code duplication because e.g. `alloc(u32, )` and `alloc(i32, )` now use the same function `allocWithFoo(4, 4, )` under the hood.
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-04-28update codebase to use `@memset` and `@memcpy`Andrew Kelley
2023-04-25update `@memcpy` to require equal src and dest lensAndrew Kelley
* Sema: upgrade operands to array pointers if possible when emitting AIR. * Implement safety checks for length mismatch and aliasing. * AIR: make ptrtoint support slice operands. Implement in LLVM backend. * C backend: implement new `@memset` semantics. `@memcpy` is not done yet.
2023-04-25change semantics of `@memcpy` and `@memset`Andrew Kelley
Now they use slices or array pointers with any element type instead of requiring byte pointers. This is a breaking enhancement to the language. The safety check for overlapping pointers will be implemented in a future commit. closes #14040
2023-02-15split `@qualCast` into `@constCast` and `@volatileCast`Veikka Tuominen
2023-02-12Revert "std: check types of pointers passed to allocator functions"Andrew Kelley
This reverts commit abc9530a88d24350481d9264edcde300f293929a. This patch implies that the idiomatic Zig way of handling anytype parameter is to write a bunch of boilerplate instead of directly accessing type information and relying on the compiler to be useful. I don't want it to be this way. It is the compiler's job to make useful error messages when the wrong field of a type info result is accessed, and it is the zig programmer's job to understand what it means when a compile error points at the field access of `@typeInfo` (along with the relevant callsites). One thing that might be useful would be having the compiler be aware of module boundaries and highlighting the boundaries of them. The first reference note after crossing a module boundary is likely the most interesting one.
2023-02-12std: check types of pointers passed to allocator functionsLeo Constantinides
2022-12-13Allocator.zig: minor fixesGanesan Rajagopal
* Remove recursive call using null alignment, since it's no longer relevant. * Fix comment
2022-12-06remove most conditional compilation based on stage1Andrew Kelley
There are still a few occurrences of "stage1" in the standard library and self-hosted compiler source, however, these instances need a bit more careful inspection to ensure no breakage.
2022-11-29std.mem.Allocator: allow shrink to failAndrew Kelley
closes #13535
2022-11-16std.mem.Allocator: do not return undefined pointers from `create`Veikka Tuominen
Closes #13517
2022-10-29Allocator: fix len_align calc in large type size casekkHAIKE
2022-10-27std.mem.Allocator: do not return undefined pointersVeikka Tuominen
2022-09-29std: Replace use of stage1 function pointersominitay
2022-07-23Revert "std.mem.Allocator: add alignedCreate"Veikka Tuominen
This reverts commit 5647a73fea7ecc9e1ee190362ef47f402eb95dff.
2022-07-23std.mem.Allocator: add alignedCreatedevins2518
2022-05-02Allocator: correct `PanicFree` function nameLee Cannon
2022-04-05zig fmt: remove trailing whitespace on doc commentsDamien Firmenich
Fixes #11353 The renderer treats comments and doc comments differently since doc comments are parsed into the Ast. This commit adds a check after getting the text for the doc comment and trims whitespace at the end before rendering. The `a = 0,` in the test is here to avoid a ParseError while parsing the test.
2022-01-26std.mem.Allocator: upgrade to new function pointer semanticsAndrew Kelley
2021-12-19Allocator: `allocBytes` and `reallocBytes` (#10352)Lee Cannon
Closes #10348
2021-12-19stage1, stage2: rename c_void to anyopaque (#10316)Isaac Freund
zig fmt now replaces c_void with anyopaque to make updating code easy.
2021-12-02allocator: Move vtable into gen structLee Cannon
2021-11-30allocgate: change resize to return optional instead of errorLee Cannon