I have trouble to create a list with 10 billions elements in Zig, like the code below. How to fix this code?
const std = @import("std");
pub fn main() !void {
const file_path = "large_array.data";
const size = 10_000_000_000;
var file = try std.fs.cwd().createFile(file_path, .{ .truncate = true });
defer file.close();
// Resize the file to 10 billion bytes
try file.resize(size);
// Memory-map the file
const mapping = try std.fs.FileMapping.init(file, 0, size);
defer mapping.deinit();
const array = mapping.asBytes();
for (array) |*byte| {
byte.* = 1; // Initialize with `1`
}
// Access example
std.debug.print("First element: {}\n", .{array[0]});
}