| author | |
| committer | |
| log | 4913de3c88d61637490bb450690d769b324508b5 |
| tree | 9651e9f565b05db0bfe72ba12e7e5bff8f0060fd |
| parent | 95a0474dc6bf26a7a86bea4c93e06b3ae0cd37cc |
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.2 files changed, 4 insertions(+), 4 deletions(-)
lib/std/heap/general_purpose_allocator.zig+3-3| ... | @@ -99,7 +99,7 @@ const math = std.math; | ... | @@ -99,7 +99,7 @@ const math = std.math; |
| 99 | const assert = std.debug.assert; | 99 | const assert = std.debug.assert; |
| 100 | const mem = std.mem; | 100 | const mem = std.mem; |
| 101 | const Allocator = std.mem.Allocator; | 101 | const Allocator = std.mem.Allocator; |
| 102 | const page_size = std.mem.page_size; | 102 | const page_size = std.heap.pageSize(); // TODO: allow this to be runtime known |
| 103 | const StackTrace = std.builtin.StackTrace; | 103 | const StackTrace = std.builtin.StackTrace; |
| 104 | 104 | ||
| 105 | /// Integer type for pointing to slots in a small allocation | 105 | /// Integer type for pointing to slots in a small allocation |
| ... | @@ -1040,8 +1040,8 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { | ... | @@ -1040,8 +1040,8 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { |
| 1040 | 1040 | ||
| 1041 | const bucket_size = bucketSize(size_class); | 1041 | const bucket_size = bucketSize(size_class); |
| 1042 | const bucket_bytes = try self.backing_allocator.alignedAlloc(u8, @alignOf(BucketHeader), bucket_size); | 1042 | const bucket_bytes = try self.backing_allocator.alignedAlloc(u8, @alignOf(BucketHeader), bucket_size); |
| 1043 | const ptr = @as(*BucketHeader, @ptrCast(bucket_bytes.ptr)); | 1043 | const ptr: *BucketHeader = @ptrCast(bucket_bytes.ptr); |
| 1044 | ptr.* = BucketHeader{ | 1044 | ptr.* = .{ |
| 1045 | .page = page.ptr, | 1045 | .page = page.ptr, |
| 1046 | .alloc_cursor = 0, | 1046 | .alloc_cursor = 0, |
| 1047 | .used_count = 0, | 1047 | .used_count = 0, |
lib/std/mem/Allocator.zig+1-1| ... | @@ -227,7 +227,7 @@ fn allocBytesWithAlignment(self: Allocator, comptime alignment: u29, byte_count: | ... | @@ -227,7 +227,7 @@ fn allocBytesWithAlignment(self: Allocator, comptime alignment: u29, byte_count: |
| 227 | const byte_ptr = self.rawAlloc(byte_count, log2a(alignment), return_address) orelse return Error.OutOfMemory; | 227 | const byte_ptr = self.rawAlloc(byte_count, log2a(alignment), return_address) orelse return Error.OutOfMemory; |
| 228 | // TODO: https://github.com/ziglang/zig/issues/4298 | 228 | // TODO: https://github.com/ziglang/zig/issues/4298 |
| 229 | @memset(byte_ptr[0..byte_count], undefined); | 229 | @memset(byte_ptr[0..byte_count], undefined); |
| 230 | return @as([*]align(alignment) u8, @alignCast(byte_ptr)); | 230 | return @alignCast(byte_ptr); |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | /// Requests to modify the size of an allocation. It is guaranteed to not move | 233 | /// Requests to modify the size of an allocation. It is guaranteed to not move |