This commit is contained in:
michal-dobrogost 2025-11-25 09:08:58 -05:00 committed by GitHub
commit a869e1e076
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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 {