Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7834971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:25:16+00:00 2026-06-02T13:25:16+00:00

Does std::vector::size() recompute the size of the vector each time it’s called, or does

  • 0

Does std::vector::size() recompute the size of the vector each time it’s called, or does it maintain a counter that is only modified when the vector is modified? For example, if I have class with a std::vector<double> member, would there be any speed benefit to keeping track of its size in a separate counter?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T13:25:27+00:00Added an answer on June 2, 2026 at 1:25 pm

    size() is guaranteed to have constant time complexity, and in any sane implementation will be as fast an operation as you can possibly have.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If std::vector and friends are self resizing, does that mean if I declare a
gprof says that my high computing app spends 53% of its time inside std::vector
When I call std::vector::reserve when the identifier is of type std::vector<Foo*> reserve(...) does nothing:
Am I right in assuming that adding/removing elements to an std::map does not effect
It says here that The unbounded array is similar to a std::vector in that
A different question inspired the following thought: Does std::vector<T> have to move all the
I'm looking for a C++ container that's a cross between boost::array, boost::scoped_array and std::vector.
I have a piece of code which creates a std::vector<T> with a known size:
I instantiate an std::vector foo(1000) . foo.size() is now 1000 and foo.capacity() is also
I'm hoping that the elements are 1 byte aligned and similarly that a std::vector<int>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.