vector::reserve() with value less than current size().

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jason.cipriani@gmail.com

    vector::reserve() with value less than current size().

    What is the official word on what happens if I call reserve() on an
    std::vector, and specify a capacity that is less than the current
    *size* (not capacity) of that vector? Is it supposed to resize() the
    vector as well? Or just not modify anything?

    Thanks,
    Jason
  • Joe Gottman

    #2
    Re: vector::reserve () with value less than current size().

    jason.cipriani@ gmail.com wrote:
    What is the official word on what happens if I call reserve() on an
    std::vector, and specify a capacity that is less than the current
    *size* (not capacity) of that vector? Is it supposed to resize() the
    vector as well? Or just not modify anything?
    >
    Thanks,
    Jason
    reserve() never reduces capacity; it just increases it. Therefore this
    is a no-op.

    Joe Gottman

    Comment

    • Salt_Peter

      #3
      Re: vector::reserve () with value less than current size().

      On Nov 18, 8:25 pm, "jason.cipri... @gmail.com"
      <jason.cipri... @gmail.comwrote :
      What is the official word on what happens if I call reserve() on an
      std::vector, and specify a capacity that is less than the current
      *size* (not capacity) of that vector? Is it supposed to resize() the
      vector as well? Or just not modify anything?
      >
      Thanks,
      Jason
      The size of the vector is irrelevant. If reserve's arguement is less
      than or equal to its capacity, nothing happens. Swap the vector to
      (maybe) change its capacity.

      Comment

      • jason.cipriani@gmail.com

        #4
        Re: vector::reserve () with value less than current size().

        On Nov 18, 8:48 pm, Joe Gottman <jgott...@carol ina.rr.comwrote :
        jason.cipri...@ gmail.com wrote:
        What is the official word on what happens if I call reserve() on an
        std::vector, and specify a capacity that is less than the current
        *size* (not capacity) of that vector? Is it supposed to resize() the
        vector as well? Or just not modify anything?
        >
        Thanks,
        Jason
        >
        reserve() never reduces capacity; it just increases it.  Therefore this
        is a no-op.
        That's what I was looking for, thanks Joe and Salt_Peter.

        Also, sorry, I'm looking now and it turns out that actually *is*
        stated in the docs I was reading, it's just in a footnote that I
        missed. :-o

        Jason

        Comment

        Working...