Question

I'm programming an old-school mmorpg in win32 (It's supposed to run on very old machines), and I want to read a file that can be either ASCII or Unicode (rarely), and count the number of lines in it. due to the fact that those machines have very very low memory, I can't keep more than 4KB at once in the RAM.

any ideas? thanks

No correct solution

OTHER TIPS

Read the file in small chunks at a time, say 1/10th the size of your memory budget. Count the line ends in each chunk.

The only real problem you face is that you need to deal with cr+lf pairs that span from the end of one chunk to the beginning of the next.

As an aside, surely you mean 4MB rather than 4KB?

Just to propose something a little different...

type foo.txt|find /C /V "~`!@#$%^&*()_+"

Or really just the following I think... been awhile

find /C /V "" foo.txt
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top