user1114365
user1114365

Reputation: 35

reading a file in win32

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

Upvotes: 0

Views: 452

Answers (2)

David Heffernan
David Heffernan

Reputation: 612784

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?

Upvotes: 2

ficuscr
ficuscr

Reputation: 7054

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

Upvotes: 0

Related Questions