max_size()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • t

    max_size()

    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?

  • Barry

    #2
    Re: max_size()

    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

    Comment

    • =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=

      #3
      Re: max_size()

      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<Tth at 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

      Comment

      • Bo Persson

        #4
        Re: max_size()

        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."




        Bo Persson


        Comment

        • James Kanze

          #5
          Re: max_size()

          On Oct 2, 9:42 am, t <tmt...@Yahoo.c omwrote:
          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:james.kan ze@gmail.com
          Conseils en informatique orientée objet/
          Beratung in objektorientier ter Datenverarbeitu ng
          9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


          Comment

          Working...