This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: vector<> can probably never grow to it's maximum size!
On Mon, 2004-10-18 at 23:07, Paolo Carlini wrote:
> Dhruv Matani wrote:
>
> >>Also, I want to see nice testcases, with custom allocators.
> >>
> >>
> >??? Like showing what kind of behaviour?
> >
> >
> So, you are 100% sure that our std::vector *never* grows above max_size?
Consider this line: vector.tcc => 432.
const size_type __len = __old_size + std::max(__old_size, __n);
Now, if vector<char> is used, then is possible for you to have
SIZE_T_MAX/2(??? like INT_MAX) chars, say in another vector, and
SIZE_T_MAX/2+1 chars in the current vector. The above line would produce
the value (SIZE_T_MAX/2+1)+(SIZE_T_MAX/2+1) = SIZE_T_MAX+2 = 2! which is
nonsense.
We should probably have a check somewhere __len > __old_size???
This is what it seems to me at first sight. Please confirm. If ever I
try to write a test-case for this, it will cause ultra-thrashing on my
machine.
However, for the record:
#include <vector>
using namespace std;
int main()
{
size_t sz = ~0;
sz >>= 1;
std::vector<int> iv1(sz+1), iv2(sz);
iv1.insert(iv1.end(), iv2.begin(), iv2.end());
}
>
> Paolo.
--
-Dhruv Matani.
http://www.geocities.com/dhruvbird/
The price of freedom is responsibility, but it's a bargain, because
freedom is priceless. ~ Hugh Downs