3 ms·
I haven't looked at this implementation yet, but your understanding is correct: reserving 4GB up-front with `std::vector` should only acquire virtual memory and
by woodruffw 5y ago
I haven't looked at this implementation yet, but your understanding is correct: reserving 4GB up-front with `std::vector` should only acquire virtual memory and not require an actual commitment, unless `std::vector` is doing something nuts internally like default-constructing each element that's been reserved. But I don't believe it does that.
- tom_ 5y agoI think you've got two sensible options in this case: commit, or do nothing. The standard's wording accommodates both: it's valid for a reserve to be a no-op, a situation the caller can detect (if they want to - assuming they even imagined anybody would ever do this! - I certainly never did, until now) by checking the new capacity. It's not obvious to me that it buys you much to reserve without committing. You're taking the hint, then ignoring it. Why bother? Why not just do nothing?r