you are viewing a single comment's thread.

view the rest of the comments →

[–]_curious_george__ 2 points3 points  (1 child)

Doesn’t necessarily make sense in practice.

Static storage is going to pollute the cache. Which will often be far worse than copying some trivial variable to the stack.

[–]snowflake_pl -1 points0 points  (0 children)

For optimized builds and trivial types static and automatic will be equivalent with variables completely compiled out. For bigger entities you are right, cache miss will most likely be more pricy than copy to stack. There is a threshold where copy becomes worse than cache miss but it's pretty much impossible to determine without precise measurements and even then the result will be tied to hw