"dotnetchic " <do********@gma il.comwrote in message
news:11******** **************@ m79g2000cwm.goo glegroups.com.. .
Thanks to you all for the quick responses. I have posted the more
complete snippet this time.
for (uj = 0; uj < * ioStruct.FrntSc rPtrn_NumItemsX ; uj++)
for (ui = 0; ui < * ioStruct.FrntSc rPtrn_NumItemsY ; ui++)
{
fread(&tempChar , sizeof(tempChar ), 1, fInput);
*(ioStruct.Frnt ScrPtrn + uj
*(*ioStruct.Frn tScrPtrn_NumIte msY)+ui) = tempChar;
}
That's about the lamest loop I've ever seen. Obviously written for
employment security. It's equivalent to the slightly faster (calling T the
element type of ioStruct.FrntSc rPtrn):
const size_t colcount = *ioStruct.FrntS crPtrn_NumItems Y;
size_t rowsleft = *ioStruct.FrntS crPtrn_NumItems X;
T* p = ioStruct.FrntSc rPtrn;
while (rowsleft-- 0)
{
size_t colsleft = colcount;
while (colsleft-- 0)
{
fread(&tempChar , sizeof(tempChar ), 1, fInput);
*(p++) = tempChar;
}
}
But that still calls fread a bunch of times, so we'll speed that up with:
when sizeof(T) == sizeof(tempChar ),
const size_t colcount = *ioStruct.FrntS crPtrn_NumItems Y;
const size_t rowcount = *ioStruct.FrntS crPtrn_NumItems X;
fread(ioStruct. FrntScrPtrn, sizeof(*ioStruc t.FrntScrPtrn), colcount *
rowcount, fInput);
or, when sizeof(T) != sizeof(tempChar ), calling T1 the type of tempChar
const size_t colcount = *ioStruct.FrntS crPtrn_NumItems Y;
const size_t rowcount = *ioStruct.FrntS crPtrn_NumItems X;
size_t elems = colcount * rowcount;
T1 *tempBuffer = (T1*)alloca(ele ms * sizeof (T1)); // pick your favorite
allocator
fread(tempBuffe r, sizeofT1), elems, fInput);
while (elems-- 0)
ioStruct.FrntSc rPtrn[elems] = tempBuffer[elems]; // compiler should
convert this to a pair of pointers...
// deallocate tempBuffer here if not using alloca or garbage collection