InvalidMemoryOperationError from File.byLine()?

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 3 01:38:17 PDT 2015


On Tuesday, June 02, 2015 19:18:13 Stiff via Digitalmars-d-learn wrote:
> Hi,
>
> I'm reading in a rather large text file (~25Mb) line by line,
> where I don't need to hang on to a line for more than one
> iteration through my loop. I'm consistently getting an
> InvalidMemoryOperationError on my 2,547th iteration, and based on
> console outputs, I'm fairly certain it's coming from the byLine()
> method. To be clear, I'm just doing a simple:
>
> foreach (line; file.byLine()){ ... }
>
> Am I possibly screwing something up? I haven't declared any
> classes or written any destructors. Is this a bug? If so, is
> there a workaround?

We'd need to see actual code which exhibited the problem in order to say
much, but it my be related to the fact that byLine reuses the buffer that it
uses for front, so you can't keep it around between iterations. If you want
to do that, you have to dup/idup it or use byLineCopy. But that's just a
shot in the dark. Without seeing actual code, it's hard to judge what could
be going on.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list