Question
Performance Penalty - On accessing a Array in a structure vs a simple array
Posted on October 12, 2015 at 18:59
Hi
I want to know whether there is penalty on accessing an array from a structure vs accessing by a simple array. Here is my snippet which i used when I faced the problemunsigned
char
array_1[10240];
typedef
struct
{
int
header;
unsgined
char
array_2[10240]
}simple_queue;
typedef
struct
{
int
top;
simple_queue simple_arr[3]
}simple_stack;
simple_stack struct_var1;
....some file open ....
f_write
(&fp, &struct_var1.simple_arr.array_2[0], 10240);
f_write
(&fp, &array_1[0], 10240);
....
So this is a file operation function which works perfectly and I could see that the performance was varying in the both steps.
What I could Observe in the benchmark test was the first f_write took 50ms time to complete , while the second f_write took only 2ms
So all that differs while comparing the two f_write are , one uses array in a structure and other uses a simple array..
Please explain me about this behavior.
#memory-organization #stm32f429