reserve(), vector allocation

This is a discussion on reserve(), vector allocation within the C++ Programming forums, part of the General Programming Boards category; When I pass reserve() a value high enough that may mean the need for reallocation, is the vector reallocated immediately ...

  1. #1
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Angola
    Posts
    7,909

    reserve(), vector allocation

    When I pass reserve() a value high enough that may mean the need for reallocation, is the vector reallocated immediately or only at next push_back()?
    Last edited by Mario F.; 06-12-2006 at 10:28 AM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,629
    Memory should be reallocated immediately.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Angola
    Posts
    7,909
    Thanks laserlight.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. capacity and reserve
    By George2 in forum C++ Programming
    Replies: 33
    Last Post: 03-06-2008, 07:14 PM
  2. reserve method of vector
    By George2 in forum C++ Programming
    Replies: 11
    Last Post: 11-15-2007, 02:24 PM
  3. airline reserve system
    By strider496 in forum C Programming
    Replies: 2
    Last Post: 04-09-2005, 02:48 PM
  4. Reserve the character in a string
    By alice in forum C Programming
    Replies: 2
    Last Post: 06-13-2004, 07:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21