473,395 Members | 1,681 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

max_size()

t
I understand size() and capacity(), but not max_size().

Lippman: c.max_size() returns maximum number of elements c can
contain, where c is a container.

This may be stupid, but I don't understand that... Maximum in terms
of what?

Oct 2 '07 #1
4 5267
t wrote:
I understand size() and capacity(), but not max_size().

Lippman: c.max_size() returns maximum number of elements c can
contain, where c is a container.

This may be stupid, but I don't understand that... Maximum in terms
of what?
IMHO
max_size() has a connection with maximum pointer available on the platform.
so on a 32-bit machine, the max_size() should be smaller the 2^32.

And moreover, Container::max_size() can implemented by
Allocator::max_size(). -- MSVC8
Oct 2 '07 #2
On 2007-10-02 09:42, t wrote:
I understand size() and capacity(), but not max_size().

Lippman: c.max_size() returns maximum number of elements c can
contain, where c is a container.

This may be stupid, but I don't understand that... Maximum in terms
of what?
It is the maximum number of elements that your implementation/platform
allows you to put in the container. For std::vector<Tthat gives me
2^32 / sizeof(T) elements, or put in another way, as many elements as I
can cram in in my 4 GiB of virtual address space provided that I do not
use it for anything else.

--
Erik Wikström
Oct 2 '07 #3
t wrote:
:: I understand size() and capacity(), but not max_size().
::
:: Lippman: c.max_size() returns maximum number of elements c can
:: contain, where c is a container.
::
:: This may be stupid, but I don't understand that... Maximum in
:: terms of what?

It's not really clear what the intention originally was, we only know
that you can never create a container larger than max_size() elements.
Normally, you cannot even get close to this number, so it is not very
useful.

This has been reported as a defect in the standard, but the committee
decided that the current wording is good enough:

"max_size() isn't useful for very many things, and the existing
wording is sufficiently clear for the few cases that max_size() can be
used for. None of the attempts to change the existing wording were an
improvement."

http://www.open-std.org/jtc1/sc22/wg...n2405.html#197
Bo Persson
Oct 2 '07 #4
On Oct 2, 9:42 am, t <tmt...@Yahoo.comwrote:
I understand size() and capacity(), but not max_size().
Lippman: c.max_size() returns maximum number of elements c can
contain, where c is a container.
This may be stupid, but I don't understand that... Maximum in
terms of what?
In terms of whatever the implementation wants. All you're
guaranteed is that attempting to create a container with more
than max_size() elements will fail, throwing length_error.
Attempting to create one with less may or may not fail,
typically throwing bad_alloc on failure.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Oct 3 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kevin Goodsell | last post by:
I was unable to locate the answer to this question in the (draft) Standard or in The C++ Standard Library (Josuttis). What should occur when one attempts to increase the size of a container beyond...
8
by: A_StClaire_ | last post by:
hey all, I'm a newb and a moronic one at that. after a day, still can't figure this thing out. trying to write a simple program that reads a (C-style) string and then a double til the user...
7
by: inkexit | last post by:
I'm getting assertion errors when I try to import or export a file using this code. Please help. I don't even know what an assertion error is. #include <iostream> #include <iomanip> #include...
2
by: alexey_m | last post by:
Hi! Code: std::map<int,MyClass*> m; int mapsize=m.max_size(); So, mapsize is -1. Can anyone tell me why? Compile with g++ 3.2.2 under Linux. Under Windows with MS Compiler everything is OK...
2
by: ravxm | last post by:
I'm trying to rotate an array of ints by one element to the left. I'm a newbie on this so please have a little patience... I want to rotate the array so if I have 12345, after one rotation I get...
13
by: theronnightstar | last post by:
I seem to be having a problem with getline(). I have tried to find it on google, but I'm not seeing the answer. The goal of this section of code is simply to read in a line from a file to a...
2
by: theronnightstar | last post by:
I am writing an anagram program for my fiance. Figured it would be an excellent task to learn from. The way it is supposed to work is it reads in a word list from a file into a temporary...
6
by: AZRebelCowgirl73 | last post by:
Here is my problem: I have two java files: One named Car.java and the other named CarDealerApp.java: In the CarDealerApp program, I read in through user input the make, model, year and price of...
1
by: AnduSe23 | last post by:
Hi, I implemented a solution for a homework assignment and everytime i run my program it crashes. could someone tell me what i'm doing wrong? I so confused what to pass into the functions when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.