I offer the first version. In the first version, an array is allocated only once. In the second version, the array is allocated with each iteration of the loop.
Although compilers can optimize allocation (for example, execute only once), I believe that factoring it tells the reader that memory is allocated only once.
This can be nothing to worry about, since many platforms are allocated on the stack, and distribution consists of changing the contents of the stack pointer.
With a dubious profile.
When considering optimization, do not do this. Spend time making the program right and reliable.
source share