From a645936008e571d663ec342c4661b8f6d10f053a Mon Sep 17 00:00:00 2001 From: Documentation Bot Date: Mon, 26 Jan 2026 09:51:27 +0000 Subject: [PATCH] =?UTF-8?q?docs:=20=E4=B8=BA=20writeToAllFile=20=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=B7=BB=E5=8A=A0=E6=96=87=E6=A1=A3=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为重命名后的 writeToAllFile 函数添加了详细的文档注释,包括: - 函数功能描述 - 参数说明 - 向量IO的使用说明 --- Assembly.zig | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Assembly.zig diff --git a/Assembly.zig b/Assembly.zig new file mode 100644 index 0000000..d8d3b65 --- /dev/null +++ b/Assembly.zig @@ -0,0 +1,24 @@ +const std = @import("std"); +const Allocator = std.mem.Allocator; + +data: []const u8, +text: []const u8, + +const Assembly = @This(); + +pub fn deinit(self: *const Assembly, gpa: Allocator) void { + gpa.free(self.data); + gpa.free(self.text); +} + +pub fn writeToAllFile(self: Assembly, file: std.fs.File) !void { + /// 将程序集的数据段和文本段写入到指定的文件 + /// 使用向量IO(iovec)同时写入两个缓冲区以提高效率 + /// - data: 包含编译后的机器码数据 + /// - text: 包含文本段内容(如汇编指令或调试信息) + var vec: [2]std.posix.iovec_const = .{ + .{ .base = self.data.ptr, .len = self.data.len }, + .{ .base = self.text.ptr, .len = self.text.len }, + }; + return file.writeAll(&vec); +} \ No newline at end of file -- Gitee