Quote:
Originally Posted by Pragma
What I was going at - but failed to mention - is what happens if you have an array that's larger than your largest block of contiguous memory? Using a vector, it's possible to store that, having it broken into chunks scattered wherever there's space, as opposed to simply going "Hrm, we need to add elements, okay, let's go find a new chunk of free memory that's current+50 bytes."
That's what happens when I don't completely explain myself
|
Except that's exactly what most implementations of vector do, including the one shipped by Microsoft. When you resize a std::vector it will typically reallocate a new array and copy what it needs to onto it. If no such block exists, such as if you have a lot of fragmented allocations (surprisngly hard to do), then std::vector will simply throw an out-of-memory exception, just as if you had tried to allocate that block using a call to new(), since that's probably exactly what it did!