AnsweredAssumed Answered

Performance Penalty - On accessing a Array in a structure vs a simple array

Question asked by arbitrer on Oct 12, 2015
Latest reply on Oct 13, 2015 by gonzalez.laurent
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 problem

unsigned 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.

Outcomes