cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : vector : max_size
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
vector
comparison operators
vector::vector
vector::~vector
member functions:
· vector::assign
· vector::at
· vector::back
· vector::begin
· vector::capacity
· vector::clear
· vector::empty
· vector::end
· vector::erase
· vector::front
· vector::get_allocator
· vector::insert
· vector::max_size
· vector::operator=
· vector::operator[]
· vector::pop_back
· vector::push_back
· vector::rbegin
· vector::rend
· vector::reserve
· vector::resize
· vector::size
· vector::swap

-

vector::max_size public member function
size_type max_size () const;

Return maximum size

Returns the maximum number of elements that the vector container can hold.

This is not the amount of storage space currently allocated to the vector (this can be obtained with member vector::capacity), but the maximum potential size the vector could reach due to system or library implementation limitations.

Parameters

none

Return Value

The maximum number of elements a vector object can have as its content.

Member type size_type is an unsigned integral type.

Example

// comparing size, capacity and max_size
#include <iostream>
#include <vector>
using namespace std;

int main ()
{
  vector<int> myvector;

  // set some content in the vector:
  for (int i=0; i<100; i++) myvector.push_back(i);

  cout << "size: " << (int) myvector.size() << "\n";
  cout << "capacity: " << (int) myvector.capacity() << "\n";
  cout << "max_size: " << (int) myvector.max_size() << "\n";
  return 0;
}

A possible output for this program could be:

size: 100
capacity: 141
max_size: 1073741823

Complexity

Constant.

See also

vector::capacity Return size of allocated storage capacity (public member function)
vector::size Return size (public member function)
vector::resize Change size (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us