This dramatically pessimizes performance for large vector sizes and doesn't actually save that much memory because all intermediate allocations are still being used by the process, so follow stdlibc++ example and just double the allocated buffer size without limit.