preallocate buffer, reducing the number of reallocations and consequently CPU usage