// Creates a 1 GiB file containing random data. import io.file; import std.parallelism : parallel; auto f = File("big_random_file.dat", FileFlags.writeNew); f.length = 1024^^3; // 1 GiB auto map = f.memoryMap!size_t(Access.write); foreach (i, ref e; parallel(map[])) e = uniform!"[]"(size_t.min, size_t.max);
Convenience function for creating a memory map.
auto tf = testFile(); immutable newData = "The quick brown fox jumps over the lazy dog."; // Modify the file { auto f = File(tf.name, FileFlags.readWriteEmpty); f.length = newData.length; auto map = f.memoryMap!char(Access.readWrite); assert(map.length == newData.length); map[] = newData[]; assert(map[0 .. newData.length] == newData[]); } // Read the file back in { auto f = File(tf.name, FileFlags.readExisting); auto map = f.memoryMap!char(Access.read); assert(map.length == newData.length); assert(map[0 .. newData.length] == newData[]); }