When std::vector
gets full, new memory is allocated. From what I read, the new capacity grows in a geometric progression (but this is irrelevant to the question), then the old information is copied in the new memory region, and the old one is freed.
Based on this assumption, my questions are:
Why don't compilers try to see if there's enough contiguous free-to-use memory at the end of our
std::vector
, allocate just a portion at the end of ourstd::vector
, and don't waste time copying?Did people try to implement this, but it was decided it's not worth to do it? (on the average/always)
Are there are any other, more subtle, reasons why this is not happening?