mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
Merge 636dc11814 into d0ba6642b5
This commit is contained in:
commit
a869e1e076
1 changed files with 20 additions and 1 deletions
|
|
@ -248,6 +248,25 @@ pub fn allocSentinel(
|
|||
return self.allocWithOptionsRetAddr(Elem, n, null, sentinel, @returnAddress());
|
||||
}
|
||||
|
||||
/// Allocates with an alignment which is incorporated into the returned type.
|
||||
/// Call `free` when done.
|
||||
///
|
||||
/// Assign to an inferred type to have a correctly specified alignment.
|
||||
/// The alignment of the type will be used by `free` later.
|
||||
/// Specifying a type may result in a silent coercion to a different alignment.
|
||||
///
|
||||
/// This is correct:
|
||||
/// ```
|
||||
/// const data = alignedAlloc(...);
|
||||
/// defer free(data);
|
||||
/// const d: []u8 = data;
|
||||
/// ```
|
||||
///
|
||||
/// This is hazardous:
|
||||
/// ```
|
||||
/// const d:[]u8 = alignedAlloc(...);
|
||||
/// defer free(d);
|
||||
/// ```
|
||||
pub fn alignedAlloc(
|
||||
self: Allocator,
|
||||
comptime T: type,
|
||||
|
|
@ -432,7 +451,7 @@ pub fn reallocAdvanced(
|
|||
return mem.bytesAsSlice(T, new_bytes);
|
||||
}
|
||||
|
||||
/// Free an array allocated with `alloc`.
|
||||
/// Free an array allocated with `alloc` or `alignedAlloc`.
|
||||
/// If memory has length 0, free is a no-op.
|
||||
/// To free a single item, see `destroy`.
|
||||
pub fn free(self: Allocator, memory: anytype) void {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue