By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,852 Members | 2,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,852 IT Pros & Developers. It's quick & easy.

Is the storage for a std::vector<T> guaranteed to be contiguous? (from FAQ)

P: n/a

I saw the following codes from the FAQ about the contiguous storage of
vector. I am just wondering how does the implementation of the <vector>
guarantee the contiguous? What if a vector v was defined first as a
5-element vector, and then was increased dramatically but the corresponding
contiguous area has already been occupied by other objects? Maybe sounds
stupid to you gurus, but it does confuse me:( Thanks.

#include <vector>
#include "Foo.h" /* get class Foo */

// old-style code that wants an array
void f(Foo* array, unsigned numFoos);

void g()
std::vector<Foo> v;
f(&v[0], v.size()); ? safe
Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.