Compiler Code Optimization - - On accessing a Array in a structure vs a simple array
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2015-10-13 9:59 PM
Posted on October 14, 2015 at 06: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]; 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
This discussion is locked. Please start a new topic to ask your question.
0 REPLIES 0
