2015-10-13 09:59 PM
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]; unsigned char array_2[10240]; typedef struct { unsgined char array_2[10240] }simple_queue; typedef struct { simple_queue simple_arr[3] }simple_stack; simple_stack struct_var1; ... .... memcpy ( char array_2, char array_1, 10240 ); memcpy (&struct_var1.simple_arr.array_2[0], char array_1, 10240 ); ....So I could see that first
memcpy()
took 90microsec, while the secondmempy()
took 310microsec. I changed theunsigned char
toint and I could see that each memcpy() took 80 microsec.
So I assume this is related to compiler optimization.. Can someone please explain to me how compiler optimization can lead to this behaviour? #memory-organization #stm32f429 #compiler