Function ensureTotalCapacityPrecise [src]

Prototype

pub fn ensureTotalCapacityPrecise(a: *Allocating, new_capacity: usize) Allocator.Error!void

Parameters

a: *Allocatingnew_capacity: usize

Source

pub fn ensureTotalCapacityPrecise(a: *Allocating, new_capacity: usize) Allocator.Error!void { const old_memory = a.writer.buffer; if (old_memory.len >= new_capacity) return; assert(new_capacity != 0); const alignment = a.alignment; if (old_memory.len > 0) { if (a.allocator.rawRemap(old_memory, alignment, new_capacity, @returnAddress())) |new| { a.writer.buffer = new[0..new_capacity]; return; } } const new_memory = (a.allocator.rawAlloc(new_capacity, alignment, @returnAddress()) orelse return error.OutOfMemory)[0..new_capacity]; const saved = old_memory[0..a.writer.end]; @memcpy(new_memory[0..saved.len], saved); if (old_memory.len != 0) a.allocator.rawFree(old_memory, alignment, @returnAddress()); a.writer.buffer = new_memory; }