New answers tagged

0

Does the compiler then optimize this array out? Probably not, because you're passing it to a function, which almost certainly means it is decaying to a pointer in the argument list. Taking the address of an object is one way to force the compiler to materialize it (ie, prevent elision). If sendBufferOverUSB happens to be inlined, the optimizer will work on ...


0

In your specific example, no, the array would not be optimized out because it gets used in the code (its address gets passed to sendBufferOverUSB). I know that arrays are created at compile time Nothing's created at compile time. When you run the program, anything declared at file scope (outside the body of a function) or with the static keyword is ...


3

"Optimized out" means the compiler realises the variable isn't necessary, and deletes the variable. For example, this code: void func(void) { int x = 0; int y = 3724832+x; printf("%d\n", y); } might be compiled the same way as: void func(void) { printf("%d\n", 3724832); } or even (if your compiler is smart enough) void func(void) { ...


1

Option 1 can have problems with cache thrashing, where cache lines get continually flushed and reloaded by threads because they all write to the same cache line. It looks like maybe you need an Option 3, using an array-of-structures rather than a structure-of-arrays. Similar to Option 1, but keeping all the workspace variables grouped together to reduce ...


Top 50 recent answers are included