What to do with InvalidMemoryOperationError
"Nordlöw" via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jan 21 05:07:10 PST 2015
On Wednesday, 21 January 2015 at 12:10:20 UTC, Nordlöw wrote:
> On Wednesday, 21 January 2015 at 12:00:47 UTC, Nordlöw wrote:
>> My executable throws as
>>
>> core.exception.InvalidMemoryOperationError@(0)
>
> I've tracked it down to being caused by
>
> foreach (line; File(path).byLine) {}
>
> when path contains a very large text file (392 MB, 1658080
> lines).
>
> Do I have any alternatives to this that doesn't trigger
> exception?
I get the exact same behaviour when I try using MmFile instead:
import std.mmfile: MmFile;
auto mmf = new MmFile(path, MmFile.Mode.read, 0, null,
pageSize);
const data = cast(char[])mmf[];
foreach (line; data.splitter('\n') {}
Does byLine use splitter? If so, maybe splitter is the problem...
More information about the Digitalmars-d-learn
mailing list