The local buffer optimization is just that—an optimization. It is a performance-oriented pattern, and we must, therefore, keep in mind the first rule of performance—never guess anything about performance. Performance, and the effect of any optimization, must be measured.
The overhead of small memory allocations
The cost of memory allocations
Since we are exploring the overhead of memory allocations and the ways to reduce it, the first question we must answer is how expensive a memory allocation is. After all, nobody wants to optimize something so fast that it needs no optimization. We can use Google Benchmark (or any other microbenchmark, if you prefer) to answer this question. The simplest benchmark to measure...