push_back
-
I need to know whether push_back when called on a vector pushes the element down the memory. In other words does a vector with push_back grow down in the memory.
-
I need to know whether push_back when called on a vector pushes the element down the memory. In other words does a vector with push_back grow down in the memory.
-
I need to know whether push_back when called on a vector pushes the element down the memory. In other words does a vector with push_back grow down in the memory.
-
I need to know whether push_back when called on a vector pushes the element down the memory. In other words does a vector with push_back grow down in the memory.
A
vector
will (is supposed to?) grow only when it needs to, so if has the capacity for 32 items, and you arepush_back(...)
-ing the 30th item, the vector should not grow (or reallocate). If you are asking how the elements in thevector
are ordered within the memory for thevector
, I believe this would be the same as a standard C-style array. That is what allows normal pointers to be used with::find(...)
and interchanged with the iterators returned byvector::begin()
andvector::end()
(except for the off-by-one for theend()
iterator). So having:vector< int > vecInt;
int iaInt[ 5 ] = { 0, 1, 2, 3, 4 };vecInt.pushBack( 0 );
vecInt.pushBack( 1 );
vecInt.pushBack( 2 );
vecInt.pushBack( 3 );
vecInt.pushBack( 4 );I believe the layout in memory for both would be the same. Peace!
-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles -
A
vector
will (is supposed to?) grow only when it needs to, so if has the capacity for 32 items, and you arepush_back(...)
-ing the 30th item, the vector should not grow (or reallocate). If you are asking how the elements in thevector
are ordered within the memory for thevector
, I believe this would be the same as a standard C-style array. That is what allows normal pointers to be used with::find(...)
and interchanged with the iterators returned byvector::begin()
andvector::end()
(except for the off-by-one for theend()
iterator). So having:vector< int > vecInt;
int iaInt[ 5 ] = { 0, 1, 2, 3, 4 };vecInt.pushBack( 0 );
vecInt.pushBack( 1 );
vecInt.pushBack( 2 );
vecInt.pushBack( 3 );
vecInt.pushBack( 4 );I believe the layout in memory for both would be the same. Peace!
-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFilesYes, vectors use contiguous memory so you can pass them to functions that take arrays like this. std::vector vecPoints; Polyline(hDC, &vecPoints[0], vecPoints.size);
Pax Domini sit semper vobiscum
-
I need to know whether push_back when called on a vector pushes the element down the memory. In other words does a vector with push_back grow down in the memory.
you can't assume anything in terms of how the algorithm is implemented, once you do you're headed for trouble when implementation changes! STL states this, it's not my personal view ;P
Yours Truly, The One and Only!