memoryMap

Convenience function for creating a memory map.

memoryMap
(
T
)
(,
Access access = Access.read
,
size_t length = 0
,
long start = 0
,
bool share = true
,
void* address = null
)

Examples

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[]);
}

Meta