tiny.tracy.TracedAllocator
Defined in tiny.tracy.
API (4)
Actions
Public operations.
Fields and members
Public fields and members.
Source
Source: lib/tracy/src/allocator.zig:8
zig
pub const TracedAllocator = struct { backing: std.mem.Allocator, name: []const u8, pub fn init(backing: std.mem.Allocator, options: Options) TracedAllocator { return .{ .backing = backing, .name = options.name, }; } pub fn allocator(self: *TracedAllocator) std.mem.Allocator { return .{ .ptr = self, .vtable = &vtable }; } const vtable: std.mem.Allocator.VTable = .{ .alloc = rawAlloc, .resize = rawResize, .remap = rawRemap, .free = rawFree, }; fn rawAlloc(ctx: *anyopaque, len: usize, alignment: std.mem.Alignment, ret_addr: usize) ?[*]u8 { const self: *TracedAllocator = @ptrCast(@alignCast(ctx)); const ptr = self.backing.rawAlloc(len, alignment, ret_addr) orelse return null; runtime.allocAddress(addressOf(ptr), len, self.name); return ptr; } fn rawResize(ctx: *anyopaque, memory: []u8, alignment: std.mem.Alignment, new_len: usize, ret_addr: usize) bool { const self: *TracedAllocator = @ptrCast(@alignCast(ctx)); const resized = self.backing.rawResize(memory, alignment, new_len, ret_addr); if (resized) self.recordResize(memory.ptr, memory.len, new_len); return resized; } fn rawRemap(ctx: *anyopaque, memory: []u8, alignment: std.mem.Alignment, new_len: usize, ret_addr: usize) ?[*]u8 { const self: *TracedAllocator = @ptrCast(@alignCast(ctx)); const ptr = self.backing.rawRemap(memory, alignment, new_len, ret_addr) orelse return null; runtime.freeAddress(addressOf(memory.ptr), memory.len, self.name); if (new_len != 0) runtime.allocAddress(addressOf(ptr), new_len, self.name); return ptr; } fn rawFree(ctx: *anyopaque, memory: []u8, alignment: std.mem.Alignment, ret_addr: usize) void { const self: *TracedAllocator = @ptrCast(@alignCast(ctx)); runtime.freeAddress(addressOf(memory.ptr), memory.len, self.name); self.backing.rawFree(memory, alignment, ret_addr); } fn recordResize(self: *TracedAllocator, ptr: [*]u8, old_len: usize, new_len: usize) void { if (old_len == new_len) return; runtime.freeAddress(addressOf(ptr), old_len, self.name); if (new_len != 0) runtime.allocAddress(addressOf(ptr), new_len, self.name); }};Source: lib/tracy/src/root.zig:38
zig
pub const TracedAllocator = allocator_mod.TracedAllocator;Audit
| Definitions | 3 |
|---|---|
| Public names | 3 |
| Members | 2 |
| Version | 26.7.0 |
| Revision | daab053ee433 |