Looks a newbie question, but this function is called many times, to be honest thousands of time per-second, so an optimization is CRUCIAL in here. What would be the best method?
struct CHOLDELEM
{
DWORD dwColor[3], dwItemId[3];
int nPos[3], nLength[3];
CItemElem* pItem[3];
CHOLDELEM()
{
for( int i=0; i<=3; i++ )
{
dwColor[i] = dwItemId[i] = 0;
nPos[i] = nLength[i] = 0;
pItem[i] = NULL;
}
}
};
or with memsets?
memset( dwColor, 0, sizeof( dwColor ) );
or another method.
memset?DWORD dwColor[3];declares an array with 3 valid indexes, namely 0, 1 and 2. There is no index 3. Trying to accessdwColor[3]is forbidden by the language; it yields undefined behavior (read: anything could happen). Thus, your loop condition should bei < 3, noti <= 3.