tiny.tldr.LinkedImage
Defined in object.
API (11)
Actions
Public operations.
Storage.Allocation.deinitStorage.Allocation.needsZeroFillStorage.allocatedeinitisMaterializedprepareIncrementalState
Types and contracts
Public types and contracts.
Fields and members
Public fields and members.
Source
Source: lib/tldr/src/object.zig:8
zig
pub const LinkedImage = struct { bytes: []u8, storage: Storage = .heap, manifest: incremental.Manifest, pub const Storage = union(enum) { heap, mapped_file: []align(std.heap.page_size_min) u8, pub const Allocation = struct { bytes: []u8, storage: Storage, pub fn deinit(self: *Allocation, allocator: std.mem.Allocator) void { switch (self.storage) { .heap => allocator.free(self.bytes), .mapped_file => |mapping| sys.memory.unmap(mapping), } self.* = undefined; } pub fn needsZeroFill(self: Allocation) bool { return switch (self.storage) { .heap => true, .mapped_file => false, }; } }; pub fn allocate( allocator: std.mem.Allocator, len: usize, options: model.LinkOptions, ) model.Error!Allocation { if (options.mapped_output_file) |file| { if (len >= options.mapped_output_min_size) { const file_len = std.math.cast(u64, len) orelse return error.OutputFileError; file.setLength(sys.fs.debugIo(), 0) catch return error.OutputFileError; file.setLength(sys.fs.debugIo(), file_len) catch return error.OutputFileError; const mapping = sys.memory.mapSharedFile(file.handle, len, .{ .read = true, .write = true }, 0) catch |err| switch (err) { error.UnsupportedPlatform => return heapAllocation(allocator, len), else => return error.OutputFileError, }; return .{ .bytes = mapping[0..len], .storage = .{ .mapped_file = mapping }, }; } } return heapAllocation(allocator, len); } fn heapAllocation(allocator: std.mem.Allocator, len: usize) model.Error!Allocation { return .{ .bytes = try allocator.alloc(u8, len), .storage = .heap, }; } }; pub fn deinit(self: *LinkedImage, allocator: std.mem.Allocator) void { switch (self.storage) { .heap => allocator.free(self.bytes), .mapped_file => |mapping| sys.memory.unmap(mapping), } self.manifest.deinit(allocator); self.* = undefined; } pub fn isMaterialized(self: LinkedImage) bool { return switch (self.storage) { .heap => false, .mapped_file => true, }; } pub fn prepareIncrementalState( self: *LinkedImage, allocator: std.mem.Allocator, ) std.mem.Allocator.Error!incremental.PreparedState { return try incremental.PreparedState.fromOwnedManifest(allocator, self.manifest.take()); }};Source: lib/tldr/src/root.zig:72
zig
pub const LinkedImage = object.LinkedImage;Audit
| Definitions | 9 |
|---|---|
| Public names | 18 |
| Members | 7 |
| Version | 26.7.0 |
| Revision | daab053ee433 |