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 8039161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:29:01+00:00 2026-06-05T03:29:01+00:00

What is the difference looking from memory menagement site between using one vector class

  • 0

What is the difference looking from memory menagement site between using one vector class member for all temp vectors used in functions:

class A
{
   private:
   vector<Type> m_vector;
}

void fnc()
{
   m_vector.clear();
   m_vector.push_back();
   //further operations on vector
}

and creating temp vectors inside of functions:

void fnc()
{
    vector<Type> vector;
    //further operations on vector
}

I suppose first option results in less memory fragmentation, cause we are doing one allocation and using this area, and in second case we are allocating memory for vectors in different functions which results in memory fragmentation.

What are the pros and cons of this vector usages? Which one should I use when I have class which needs many vectors in its functions? And which one is better looking from memory menagement site?

  • 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-05T03:29:03+00:00Added an answer on June 5, 2026 at 3:29 am

    Your solution might be better from memory management point of view because of fragmentation and fewer allocations/deallocations but :

    • You become less thread safe in a multithreaded environment – you might need to implement some synchronization in each method around the use of the vector
    • You need to remember to clear the vector’s contents in each method
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using System V Shared Memory to communicate between my two PHP applications. One
Can anyone break it down in plain English the performance difference between using temp
I'm looking for a way to determine the difference between two dates. A normal
I'm looking for a way to find the number of hours of difference between
I am looking at differences between using WPF in .NET or using Silverlight 4
I know the difference in memory usage between byte, unsigned short, and integer, but
My question is slightly different from Looking for a recommendation for a lightweight mobile
I am looking at a way to access parameter passed from different Url to
I looking for some information about the difference of the different session types available
Looking at different options: One is to just put the static pages in the

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.