Import std.io.mapped
std.io.mapped
std.io's mapped files: a file's bytes mapped into memory, read and written in place, without copying the file in, which the OS pages in as they're used.
std/io/mapped.fb
Types
MappedFile
class
Public Class MappedFile
A file mapped into memory whole, read-only or writable, until it's closed or its last reference goes. Writing to a writable one changes the file, which Flush puts onto the disk. It has the bytes the file had when it was mapped: one that grows meanwhile isn't mapped again, and on POSIX, reading what a file that another program shortens no longer has ends the program, as it would C's. On Windows, a mapped file can't be replaced or shortened until it's closed, and a write that would is BUSY, but it can be deleted.
-
The file it maps.
-
Whether it was mapped to write.
-
Maps the file, which has to be there, read-only, or writable when
writableis True. -
How many bytes it has: the file's, or 0 once it's closed.
-
Whether it's still mapped.
-
The byte at
index, from 0. Panics when it's closed, or the index is out of range. -
Sets the byte at
index. Panics when it's read-only or closed, or the index is out of range. -
A copy of
countbytes fromstart. Panics when it's closed, or they aren't all in it. -
Puts the
bytesatstart, over what's there. Panics when it's read-only or closed, or they don't all fit. -
Puts what's been written onto the disk, as File's atomic writes do theirs. A read-only or closed one has nothing to put there.
-
Its bytes as a
Buffer<UInt8>, without copying them, for streams and C code to read in place. The Buffer, and each view of it, keeps them mapped while it is, even once this is closed. A writable one's Buffer is its bytes, so writing it changes the file, as []= does. A read-only one's Buffers share a view of their own, which copies a page of the file's as it's first written, so writing one changes every Buffer this gives, before it and after, but never the file or what [] reads. Throws an IOError when that view can't be made, the first time, and panics when it's closed. -
Unmaps it, and closes the file, which a second Close leaves alone, once no Buffer from Bytes is left. What was written stays in the file, for the OS to put onto the disk.
Report an issue with this page or with FutureBlitz on GitHub.