Re: CStdioFile... with a twist (please)
Thank you for taking the time to post an algorithm, Joe.
Your observations have, of course, hit on the issues that I've come
across. CString operations are the biggest time suckers for sure (the
file is ASCII but the code must be UNICODE). I wonder, though, about
loading the entire file at once... somehow I had convinced myself that
it would slow things down.
The test file is small, approx. 4 MB (the "real" one 60~90 MB). I'll
add this code to the benchmark and see how it fares.
On Aug 4, 10:15 pm, Joseph M. Newcomer <newco...@flounder.com> wrote:
How large are your files?
CFile f;
if(!f.Open(....))
deal with error
ULONGLONG size = f.GetLength();
ASSERT(size <= 0x0FFFFFFFull);
// Arbitrary choice of maximum length; you are probably in trouble
// if it is > 100MB or so, and the code below won't work, so you
// might choose a smaller length, e.g.
// ASSERT(size < 100000000ull);
CStringA b;
LPSTR p = b.GetBuffer(size + 1);
f,Read(p, size);
p[size] = '\0';
b,ReleaseBufferSetLength((int)size);
// Using ReleaseBufferSetLength means it doesn't have to search
// for the terminating NUL character to determine the length
int start = 0;
while(true)
{
int n = b.Find('X', start);
if(n < 0)
{ /* not found */
everything from start to end of string is the record o=
f interest
break;
} /* not found */
everything from start to n-1 is the record of interest
start = n + 1;
}
This is rather simplistic, but if you don't try to create intermediate CS=
trings it can be
very fast. It works well only for small files (say, < 100MB). For l=
arger files, you
would apply the technique above to a memory-mapped file (there is some tr=
ickiness and you
can't use CStringA in this case, you have to go a bit lower-level because=
the strings will
not necessarily be NULL-terminated at the endpoint, and you have to deal =
with windowing
the mapping view into the larger file, but I'll assume your files are of =
moderate size and
therefore this more complex solution is not needed)
=
joe
On Mon, 4 Aug 2008 00:00:30 -0700 (PDT), Alexander <the44s...@yahoo.com> =
wrote:
Ok. I've written a couple of implementations (derived from CStdioFile
and streams). They work fine but are much slower than CStdioFile which
is slow to being with. I need something fast for this.
Any ideas?
On Aug 4, 2:05 pm, "Check Abdoul" <check abdoul at mvps dot org>
wrote:
Derive a subclass from CStdioFile and overwrite ReadString() =
function
and change its implementation[ ReadString() is virtual ]
Cheers
Check Abdoul
---------------------
"Alexander" <the44s...@yahoo.com> wrote in message
news:94225650-b700-490b-a1c8-c62a71f52700@a6g2000prm.googlegroups.com..=
..
I need a class exactly like CStdioFile but that on ReadString fetches
up to a character other than EOL.
Does such a thing exists? Thank you all.
Joseph M. Newcomer [MVP]
email: newco...@flounder.com
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm