Hi,
Can someone shed some light on whether recalculating a value is faster or slower than calculating and then storing and retrieving the value.
I understand that amount of time the value is needed will have an effect on the answer. So here is an example:
Code:
int i, j, tmp;
for (i = 0; i < max; i++)
{
for (j = 0; j < max - i; j++)
{
if (strcmp(array[j].word, array[j + 1].word) > 0)
{
memcpy(&temp, array[j], sizeof(struct _menu_item));
memcpy(array[j], array[j + 1], sizeof(struct _menu_item));
memcpy(array[j + 1], &temp, sizeof(struct _menu_item));
}
}
}
The above code shows that the 'sizeof(struct _menu_item)' is used 3 separate times. In this example, would it be more efficient to calculate the 'sizeof(struct _menu_item)' and store it, and then use the variable instead of the recalculating 2 more times?
Ty