由于两个版本的代码都分配了比所需数量更多的元素,因此两个版本都是正确的。 这不应导致任何错误。
它使用更多的较小分配(因此具有更多分配开销),但节省了内存。 我们建议您执行一些性能分析,以查看分配是否有明显的性能开销。
Since both versions of the code are allocating more elements than required, both versions are correct. This should not lead to any error.
It uses more smaller allocations (and thus have more allocation overhead) but saves memory. We would advise you to perform some profiling in order to see whether the allocations have a noticable performance overhead.