"dotnetchic" <do********@gmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
Thanks to you all for the quick responses. I have posted the more
complete snippet this time.
for (uj = 0; uj < * ioStruct.FrntScrPtrn_NumItemsX; uj++)
for (ui = 0; ui < * ioStruct.FrntScrPtrn_NumItemsY; ui++)
{
fread(&tempChar, sizeof(tempChar), 1, fInput);
*(ioStruct.FrntScrPtrn + uj
*(*ioStruct.FrntScrPtrn_NumItemsY)+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.FrntScrPtrn):
const size_t colcount = *ioStruct.FrntScrPtrn_NumItemsY;
size_t rowsleft = *ioStruct.FrntScrPtrn_NumItemsX;
T* p = ioStruct.FrntScrPtrn;
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.FrntScrPtrn_NumItemsY;
const size_t rowcount = *ioStruct.FrntScrPtrn_NumItemsX;
fread(ioStruct.FrntScrPtrn, sizeof(*ioStruct.FrntScrPtrn), colcount *
rowcount, fInput);
or, when sizeof(T) != sizeof(tempChar), calling T1 the type of tempChar
const size_t colcount = *ioStruct.FrntScrPtrn_NumItemsY;
const size_t rowcount = *ioStruct.FrntScrPtrn_NumItemsX;
size_t elems = colcount * rowcount;
T1 *tempBuffer = (T1*)alloca(elems * sizeof (T1)); // pick your favorite
allocator
fread(tempBuffer, sizeofT1), elems, fInput);
while (elems-- 0)
ioStruct.FrntScrPtrn[elems] = tempBuffer[elems]; // compiler should
convert this to a pair of pointers...
// deallocate tempBuffer here if not using alloca or garbage collection