pub fn destroy(self: Allocator, ptr: anytype) void self: Allocatorptr181
182
183
184
185
186
187
188
189
190
191
192pub fn destroy(self: Allocator, ptr: anytype) void {
const info = @typeInfo(@TypeOf(ptr)).pointer;
if (info.size != .one) @compileError("ptr must be a single item pointer");
const T = info.child;
if (@sizeOf(T) == 0) return;
const non_const_ptr = @as([*]u8, @ptrCast(@constCast(ptr)));
self.rawFree(
non_const_ptr[0..@sizeOf(T)],
.fromByteUnits(info.attrs.@"align" orelse @alignOf(T)),
@returnAddress(),
);
}
ptrshould be the return value ofcreate, or otherwise have the same address and alignment property.