std.mmfile

Read and write memory mapped files.

Memory mapped files are a mechanism in operating systems that allows file access through virtual memory. After opening a file with MmFile, the contents can be read from or written to with standard slice / pointer operations. Changes to the memory are automatically reflected in the underlying file.

Memory mapping can increase I/O performance of large files, compared to buffered read / write operations from std.file and std.stdio. However, I/O errors are not handled as safely: when for example the disk that the file is on gets removed, reading from it may result in a segfault.

class MmFile

Types 1

classMmFile

MmFile objects control the memory mapped file resource.

Fields
string filename
void[] data
ulong start
size_t window
ulong size
Mode mMode
void * address
Methods
void flush()
ulong length() @property constGives size in bytes of the memory mapped file.
Mode mode()Read-only property returning the file mode.
void[] opSlice()Returns entire file contents as an array.
void[] opSlice(ulong i1, ulong i2)Returns slice of file contents as an array.
ubyte opIndex(ulong i)Returns byte at index i in file.
ubyte opIndexAssign(ubyte value, ulong i)Sets and returns byte at index i in file to value.
private int mapped(ulong i)
private void unmap()
private void map(ulong start, size_t len)
private void ensureMapped(ulong i)
private void ensureMapped(ulong i, ulong j)
Constructors
this(string filename)Open memory mapped file filename for reading. File is closed when the object instance is deleted. Throws: - On POSIX, ErrnoException. - On Windows, WindowsException.
this(string filename, Mode mode, ulong size, void * address, size_t window = 0)Open memory mapped file filename in mode. File is closed when the object instance is deleted. Params: filename = name of the file. If null, an anonymous file mapping is created. mode = access mode ...
Destructors
~thisFlushes pending output and closes the memory mapped file.
Nested Templates
ModeThe mode the memory mapped file is opened with.