memory-mapped files
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Feb 17 17:30:12 PST 2009
Indeed, time and again, "testing is believing".
I tried a simple line splitting program in D with and without memory
mapping against a 140MB file. The program just reads the entire file and
does some simple string processing on it.
The loop pattern looks like this:
foreach (line; byLineDirect(stdin))
{
auto r = splitter(line, "|||");
write(r.head, ":");
r.next;
writeln(r.head);
}
The byLineDirect returns a range that uses memory mapped files when
possible, or simple fread calls otherwise.
The memory-mapped version takes 2.15 seconds on average. I was fighting
against Perl's equivalent 2.45. At some point I decided to try without
memory mapping and I consistently got 1.75 seconds. What the heck is
going on? When does memory mapping actually help?
Andrei
More information about the Digitalmars-d
mailing list