mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 15:42:49 +00:00
std.heap.GeneralPurposeAllocator: add never_unmap
config option
This is a temporary debugging trick you can use to turn segfaults into more helpful logged error messages with stack trace details. The downside is that every allocation will be leaked!
This commit is contained in:
parent
5547abd2d1
commit
583b843803
@ -142,6 +142,11 @@ pub const Config = struct {
|
||||
|
||||
/// Whether the allocator may be used simultaneously from multiple threads.
|
||||
thread_safe: bool = !std.builtin.single_threaded,
|
||||
|
||||
/// This is a temporary debugging trick you can use to turn segfaults into more helpful
|
||||
/// logged error messages with stack trace details. The downside is that every allocation
|
||||
/// will be leaked!
|
||||
never_unmap: bool = false,
|
||||
};
|
||||
|
||||
pub fn GeneralPurposeAllocator(comptime config: Config) type {
|
||||
@ -416,7 +421,9 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
|
||||
bucket.prev.next = bucket.next;
|
||||
self.buckets[bucket_index] = bucket.prev;
|
||||
}
|
||||
if (!config.never_unmap) {
|
||||
self.backing_allocator.free(bucket.page[0..page_size]);
|
||||
}
|
||||
const bucket_size = bucketSize(size_class);
|
||||
const bucket_slice = @ptrCast([*]align(@alignOf(BucketHeader)) u8, bucket)[0..bucket_size];
|
||||
self.backing_allocator.free(bucket_slice);
|
||||
|
Loading…
Reference in New Issue
Block a user