On Mon, 2003-10-06 at 15:40, Stefan Hundhammer wrote:
On Monday 06 October 2003 15:31, Sebastian Huber wrote:
Das setzt allerdings voraus, dass std::vector<T> intern zusammenhaengende Felder benutzt, was aber glaube ich jede Implementierung so macht.
Das halte ich für eine sehr gewagte Annahme. Das wird früher oder später kläglich scheitern!
Josuttis (The Standard C++ Library), Kap. 6.2.3: The C++ standard library does not state clearly whether the elements of a vector are required to be in congiguous memory. However, it is the intention that this is guaranteed and it will be fixed due to a defect report. Thus you can expect that for any valid index i in vector v, the following yields true: &v[i] == &v[0] + i This guarantee has some important consequences. It simply means that you can use a vector in cases in which you could use a dynamic array. For example, you can use a vector to hold data of oridinary C-strings of type char* or const char*: std::vector<char> v; v.resize(41); strcpy(&v[0],"hello, world" ); printf("%s\n", &v[0]); Ralf