Copying stuff in memory

This is common for all the programming language.

In the first method, you need reallocate space many times, maybe this is the largest cost, not the copy itself.

In the last method, you only need to check the bound or what else one time, and the compiler can optimise for batch process.