I have a function which will be called many times throughout my code. This function updates 2 values(passed as argument) in an array. Since it is called too many times, I want this function optimized.
Yes I do have a simplest code to do that,
int global_array[MAX];
int * ptr_to_my_global_array = &global_array[0];
main()
{
int a=0,b=0;
my_func(a,b);
a++;b++;
my_func(a,b);
a++;b++;
my_func(a,b);
a++;b++;
my_func(a,b);
a++;b++;
my_func(a,b);
a++;b++;
//and so on
}
void my_func(int c,int d)
{
*ptr_to_my_global_array = c;
ptr_to_my_global_array++;
*ptr_to_my_global_array = d;
ptr_to_my_global_array++;
}
Please do not suggest any mem_copy,mem_set solutions. There may be no other solution, but was just curious if I could make this faster.