mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 13:30:45 +00:00
GeneralPurposeAllocator: minimal fix
This keeps the implementation matching master branch, however, introduces a compile error that applications can work around by explicitly setting page_size_max and page_size_min to match their computer's settings, in the case that those values are not already equal. I plan to rework this allocator in a follow-up enhancement with the goal of reducing total active memory mappings.
This commit is contained in:
parent
95a0474dc6
commit
4913de3c88
@ -99,7 +99,7 @@ const math = std.math;
|
||||
const assert = std.debug.assert;
|
||||
const mem = std.mem;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const page_size = std.mem.page_size;
|
||||
const page_size = std.heap.pageSize(); // TODO: allow this to be runtime known
|
||||
const StackTrace = std.builtin.StackTrace;
|
||||
|
||||
/// Integer type for pointing to slots in a small allocation
|
||||
@ -1040,8 +1040,8 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
|
||||
|
||||
const bucket_size = bucketSize(size_class);
|
||||
const bucket_bytes = try self.backing_allocator.alignedAlloc(u8, @alignOf(BucketHeader), bucket_size);
|
||||
const ptr = @as(*BucketHeader, @ptrCast(bucket_bytes.ptr));
|
||||
ptr.* = BucketHeader{
|
||||
const ptr: *BucketHeader = @ptrCast(bucket_bytes.ptr);
|
||||
ptr.* = .{
|
||||
.page = page.ptr,
|
||||
.alloc_cursor = 0,
|
||||
.used_count = 0,
|
||||
|
||||
@ -227,7 +227,7 @@ fn allocBytesWithAlignment(self: Allocator, comptime alignment: u29, byte_count:
|
||||
const byte_ptr = self.rawAlloc(byte_count, log2a(alignment), return_address) orelse return Error.OutOfMemory;
|
||||
// TODO: https://github.com/ziglang/zig/issues/4298
|
||||
@memset(byte_ptr[0..byte_count], undefined);
|
||||
return @as([*]align(alignment) u8, @alignCast(byte_ptr));
|
||||
return @alignCast(byte_ptr);
|
||||
}
|
||||
|
||||
/// Requests to modify the size of an allocation. It is guaranteed to not move
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user