I have been using std::vector
a lot, and recently I asked myself this question: \"How is std::vector
implemented?\"
I had two alternatives:
There's no actual array at all in any decent implementation (if there is, you can't use any object in it without a default constructor), but just raw memory that gets allocated. It gets allocated in a manner that's usually along the lines of doubling every time you need to expand it.
The vector then uses in place allocation to call the constructors of the class in the proper location once each slot actually gets used actually used.
When there is expansion it will try to reallocate in place (but this is a bit silly and doesn't normally work, think windows 98 heap compaction) but usually will end up making a whole new allocation and copying over.
A standard stl vector is always all together, but not all implementations work like that (I know, having written some of them). Probably none are exactly a linked list, though, either.