C++ vector max_size(); -


on 32 bit system.

  1. std::vector<char>::max_size() returns 232-1, size of char — 1 byte
  2. std::vector<int>::max_size() returns 230-1, size of int — 4 byte
  3. std::vector<double>::max_size() returns 229-1, size of double — 8 byte

can tell me max_size() depends on what?

and return value of max_size() if runs on 64 bit system.

max_size() theoretical maximum number of items put in vector. on 32-bit system, in theory allocate 4gb == 2^32 2^32 char values, 2^30 int values or 2^29 double values. appear implementation using value, subtracting 1.

of course, never allocate vector big; you'll run out of memory long before then.

there no requirement on value max_size() returns other cannot allocate vector bigger that. on 64-bit system might return 2^64-1 char, or might return smaller value because system has limited memory space. 64-bit pcs limited 48-bit address space anyway.


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -