I have a function
pub fn write(this: *This, byte: u8) !void {
const gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer std.debug.assert(gpa.deinit() == .ok);
const allocator = gpa.allocator();
if (this.capacity < this.count + 1) {
const old = this.capacity;
this.capacity = increaseCapacity(old);
this.code = allocator.realloc(this.code, this.capacity);
}
this.code[this.count] = byte;
this.count += 1;
}
after running this function in test
test "writes byte to the code" {
const chunk: *Chunk = try Chunk.init(testing_allocator);
const expected: u8 = 0x1;
const added: usize = 1;
try chunk.write(expected);
const actual = chunk.code[0];
try std.testing.expectEqual(chunk.code.len, CAPACITY_THRESHOLD);
try std.testing.expectEqual(chunk.count, added);
try std.testing.expect(actual == expected);
}
I’m getting an error, that confuses me a bit:
error: expected type '*heap.general_purpose_allocator.GeneralPurposeAllocator(.{ .stack_trace_frames = 10, .enable_memory_limit = false, .safety = true, .thread_safe = true, .MutexType = null, .never_unmap = false, .retain_metadata = false, .verbose_log = false })', found '*const heap.general_purpose_allocator.GeneralPurposeAllocator(.{ .stack_trace_frames = 10, .enable_memory_limit = false, .safety = true, .thread_safe = true, .MutexType = null, .never_unmap = false, .retain_metadata = false, .verbose_log = false })'
in const allocator = gpa.allocator();
Can someone explain what happens and why?