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

  • SEARCH
  • Home
  • 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 446289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:27:21+00:00 2026-05-12T21:27:21+00:00

Referring to article Gotw 54 by HerbSutter, he explains about The Right Way To

  • 0

Referring to article Gotw 54 by HerbSutter, he explains about

  1. The Right Way To “Shrink-To-Fit” a
    vector or deque and

  2. The Right Way to Completely Clear a vector or
    deque

Can we just use container.resize()
and container.clear() for the above task
or am I missing something?

  • 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-05-12T21:27:22+00:00Added an answer on May 12, 2026 at 9:27 pm

    There are two different things that a vector holds: size Vs capacity. If you just resize the vector, there is no guarantee that the capacity(how much memory is reserved) must change. resize is an operation concerned with how much are you using, not how much the vector capacity is.

    So for example.

    size     == how much you are using
    capacity == how much memory is reserved
    vector<int> v(10);
    
    v.resize(5); // size == 5 but capacity (may or may) not be changed
    v.clear()    // size == 0 but capacity (may or may) not be changed
    

    In the end, capacity should not changed on every operation, because that would bring a lot of memory allocation/deallocation overhead. He is saying that if you need to “deallocate” the memory reserved by vector, do that.

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

Sidebar

Related Questions

By referring Joel's Article Some people are under the misconception that Unicode is simply
I was referring to an article which focuses on Speeding up LINQ to SQL
Referring to Brian Goetz's article Are all stateful Web applications broken? for IBM developerWorks,
Referring to this question , how can i get the current page size in
Referring to the first answer about python's bound and unbound methods here, I have
Referring to the Configuration Manager under the Build menu, Is there a way to
Referring to What is the correct way to make a custom .NET Exception serializable?
I'm creating an extender control by referring this article , but I'm facing hard
How does tension relate to cubic spline interpolation? I am referring to this article
Edited........ sorry Sir I was referring this piece of code from Stephen Toub's article..

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.