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 ...
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 ...
"Optimized out" means the compiler realises the variable isn't necessary, and deletes the variable. For example, this code:
int x = 0;
int y = 3724832+x;
might be compiled the same way as:
or even (if your compiler is smart enough)
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 ...