I am *not* sure if the following code is correct, it's copied from another source and I've never used memory-mapped files before: module test; import std.algorithm; import std.mmfile; void readfile(string filename) { string[] lines; auto fFile = new MmFile(filename); auto fBuffer = cast(char*)(fFile[].ptr); auto fLength = cast(size_t)fFile.length; auto textData = fBuffer[0 .. fLength]; foreach (char[] line; splitter(textData, "\n")) lines ~= line.idup; } void main() { readfile("datetime.d"); } This only happens when reading large files like std.datetime: $ dmd test.d && test.exe ok $ dmd -O test.d && test.exe object.Error: Access Violation ---------------- ---------------- ddbg says: Unhandled Exception: EXCEPTION_ACCESS_VIOLATION(0xc0000005) at std.algorithm.find!(pred,ubyte[],ubyte[]).find D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d:2885 (0x00402b23) thread(2408) That's why I've labeled is as a Phobos bug. But maybe it's a bug in the user code?
Note that this executes correctly (even with -O) when we replace "\n" (LF) by "\r\n" (CR+LF) under Windows: foreach (char[] line; splitter(textData, "\r\n")) lines ~= line.idup; Yet datetime.d is in Unix format according to my editor !
See also issue 7689
Works with latest DMD.