c - Use an array of pointers to structs, or just an array of structs? -


i'm working on fft algorithm in c microcontroller, , having trouble deciding on whether have real , imaginary parts of input data stored in array of structs, or use pointers array of structs. i'm facing conflicting requirements that code has run in tiny amount of memory, , yet fast possible. believe array of pointers structs have larger memory overhead, there's line in code following:

for (uint8_t = 0; < record_size; i++) {     uint8_t decimatevalue = fft_decimate(i);     fftdata[i]->realpart = ffttempdata[decimatevalue]->realpart;     fftdata[i]->impart = ffttempdata[decimatevalue]->impart; } 

i'm thinking if use array of pointers structs in above example compiled code faster reshuffling pointers, rather copying data between 2 data structures array-of-structures implementation would. i'm willing sacrifice memory if above section of code runs fast possible. advice.

every time access data through array of pointers, have 2 memory accesses. comes pipeline stall, on microcontrollers (unless it's small microcontroller no pipeline).

then have consider size of data. how big pointer? 2 bytes? 4 bytes? how big structs? 4 bytes? 8 bytes?

if struct twice big pointer, shuffling data half expensive pointers. however, reading or modifying data in other way more expensive. depends on program does. if spend lot of time reading data , little time shuffling it, optimize reading data. other people have right -- profile. make sure profile on microcontroller, not on workstation.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -