What is the usage limit of .push_back ()?

2

I often use .push_back(element) when working with vector , but I do not know what the maximum amount of elements I can add to a vector before it overflows and performs the reallocation of a new space in memory.

Is there a mechanism I can use to know the maximum number of elements that vector supports? This value is always the same, so if compiling for any machine this value will not change?

    
asked by anonymous 01.11.2017 / 23:10

1 answer

2

This is implementation-dependent and can vary depending on the architecture, compiler, version, and even extra factors as per usage, so it can not work with a number.

I believe most implementations will double the space allocated to each relocation.

You can give an initial value or do the resizing manually before it does automatic .

    
01.11.2017 / 23:25