Imagine the following declaration:
void foo(){ const std::array<int, 80000> arr = {/* a lot of different values*/}; //do stuff } And a second one:
void foo(){ static const std::array<int, 80000> arr = {/* a lot of different values*/}; //do stuff } What are the possible performance differences between these two if any? And is there any danger associated with any of these solutions?
staticcase they may not be on the stack, but in a read-only section. Probably compiler dependent as well.withoutStaticbuilds the array each times it is invoked from static data (.LC0).withStaticuses an array whose construction has been optimized as a constant (withStatic()::arr).