| ... | @@ -317,7 +317,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { | ... | @@ -317,7 +317,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { |
| 317 | } | 317 | } |
| 318 | } | 318 | } |
| 319 | for (self.large_allocations.items()) |*large_alloc| { | 319 | for (self.large_allocations.items()) |*large_alloc| { |
| 320 | std.debug.print("\nMemory leak detected:\n", .{}); | 320 | std.debug.print("\nMemory leak detected (0x{x}):\n", .{@ptrToInt(large_alloc.value.bytes.ptr)}); |
| 321 | large_alloc.value.dumpStackTrace(); | 321 | large_alloc.value.dumpStackTrace(); |
| 322 | leaks = true; | 322 | leaks = true; |
| 323 | } | 323 | } |
| ... | @@ -788,8 +788,15 @@ test "shrink large object to large object with larger alignment" { | ... | @@ -788,8 +788,15 @@ test "shrink large object to large object with larger alignment" { |
| 788 | var slice = try allocator.alignedAlloc(u8, 16, alloc_size); | 788 | var slice = try allocator.alignedAlloc(u8, 16, alloc_size); |
| 789 | defer allocator.free(slice); | 789 | defer allocator.free(slice); |
| 790 | | 790 | |
| | 791 | const big_alignment: usize = switch (std.Target.current.os.tag) { |
| | 792 | .windows => page_size * 32, // Windows aligns to 64K. |
| | 793 | else => page_size * 2, |
| | 794 | }; |
| | 795 | // This loop allocates until we find a page that is not aligned to the big |
| | 796 | // alignment. Then we shrink the allocation after the loop, but increase the |
| | 797 | // alignment to the higher one, that we know will force it to realloc. |
| 791 | var stuff_to_free = std.ArrayList([]align(16) u8).init(debug_allocator); | 798 | var stuff_to_free = std.ArrayList([]align(16) u8).init(debug_allocator); |
| 792 | while (mem.isAligned(@ptrToInt(slice.ptr), page_size * 2)) { | 799 | while (mem.isAligned(@ptrToInt(slice.ptr), big_alignment)) { |
| 793 | try stuff_to_free.append(slice); | 800 | try stuff_to_free.append(slice); |
| 794 | slice = try allocator.alignedAlloc(u8, 16, alloc_size); | 801 | slice = try allocator.alignedAlloc(u8, 16, alloc_size); |
| 795 | } | 802 | } |
| ... | @@ -799,7 +806,7 @@ test "shrink large object to large object with larger alignment" { | ... | @@ -799,7 +806,7 @@ test "shrink large object to large object with larger alignment" { |
| 799 | slice[0] = 0x12; | 806 | slice[0] = 0x12; |
| 800 | slice[60] = 0x34; | 807 | slice[60] = 0x34; |
| 801 | | 808 | |
| 802 | slice = try allocator.reallocAdvanced(slice, page_size * 2, alloc_size / 2, .exact); | 809 | slice = try allocator.reallocAdvanced(slice, big_alignment, alloc_size / 2, .exact); |
| 803 | std.testing.expect(slice[0] == 0x12); | 810 | std.testing.expect(slice[0] == 0x12); |
| 804 | std.testing.expect(slice[60] == 0x34); | 811 | std.testing.expect(slice[60] == 0x34); |
| 805 | } | 812 | } |
| ... | @@ -839,8 +846,13 @@ test "realloc large object to larger alignment" { | ... | @@ -839,8 +846,13 @@ test "realloc large object to larger alignment" { |
| 839 | var slice = try allocator.alignedAlloc(u8, 16, page_size * 2 + 50); | 846 | var slice = try allocator.alignedAlloc(u8, 16, page_size * 2 + 50); |
| 840 | defer allocator.free(slice); | 847 | defer allocator.free(slice); |
| 841 | | 848 | |
| | 849 | const big_alignment: usize = switch (std.Target.current.os.tag) { |
| | 850 | .windows => page_size * 32, // Windows aligns to 64K. |
| | 851 | else => page_size * 2, |
| | 852 | }; |
| | 853 | // This loop allocates until we find a page that is not aligned to the big alignment. |
| 842 | var stuff_to_free = std.ArrayList([]align(16) u8).init(debug_allocator); | 854 | var stuff_to_free = std.ArrayList([]align(16) u8).init(debug_allocator); |
| 843 | while (mem.isAligned(@ptrToInt(slice.ptr), page_size * 2)) { | 855 | while (mem.isAligned(@ptrToInt(slice.ptr), big_alignment)) { |
| 844 | try stuff_to_free.append(slice); | 856 | try stuff_to_free.append(slice); |
| 845 | slice = try allocator.alignedAlloc(u8, 16, page_size * 2 + 50); | 857 | slice = try allocator.alignedAlloc(u8, 16, page_size * 2 + 50); |
| 846 | } | 858 | } |
| ... | @@ -858,7 +870,7 @@ test "realloc large object to larger alignment" { | ... | @@ -858,7 +870,7 @@ test "realloc large object to larger alignment" { |
| 858 | std.testing.expect(slice[0] == 0x12); | 870 | std.testing.expect(slice[0] == 0x12); |
| 859 | std.testing.expect(slice[16] == 0x34); | 871 | std.testing.expect(slice[16] == 0x34); |
| 860 | | 872 | |
| 861 | slice = try allocator.reallocAdvanced(slice, page_size * 2, page_size * 2 + 100, .exact); | 873 | slice = try allocator.reallocAdvanced(slice, big_alignment, page_size * 2 + 100, .exact); |
| 862 | std.testing.expect(slice[0] == 0x12); | 874 | std.testing.expect(slice[0] == 0x12); |
| 863 | std.testing.expect(slice[16] == 0x34); | 875 | std.testing.expect(slice[16] == 0x34); |
| 864 | } | 876 | } |