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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:20:47+00:00 2026-05-23T09:20:47+00:00

I am experiencing unexpected performance degradation when using vectors with classes. I have a

  • 0

I am experiencing unexpected performance degradation when using vectors with classes.

I have a csv_File class that reads in a csv file and stores the contents in a 2D vector. There’s a member function that allows access, e.g.

    csv_File file("file.csv");
    file.access(2,2);

To access the 2,2 element.

Then, I have another class csv_Array that stores multiple csv_File objects in a vector, e.g private member vector
There’s a member function that allows access, i.e. it returns a csv_File object, for example:

    csv_Array file_array(5); //store 5 csv_File objects
    file_array.grab(0).access(2,2); 

In the second line, grab returns a csv_File object (in this case, the first one) and access is a member function of the csv_File object.

However, I have noticed that the call
csv_Array.grab(0).access(2,2);
is much slower than it should be (it should be just 3 vector::at calls).

Is there some sort of hidden copy going on that is making this very slow?

EDIT: Here are some of the relevant function prototypes:

    //Access in csv_File
    std::string access(int row, int column);

    //grab in csv_Array and csv_Analysis (mentioned below)
    csv_File grab(int index);

ADDITIONAL DETAILS (if necessary):
The application of this code is to load a bunch of csv files into memory before passing it to a friend class that will do some calculations with the data. Schematically, I have the following:

1) csv_Array has private member vector storage;
2) csv_Analysis is a class that is a friend of csv_Array
3) csv_Analysis accesses vector storage, which is in csv_Array
4) This access is done by passing csv_Analysis a reference to storage in csv_Array (so no copy hopefully….), e.g
public:
csv_Analysis(csv_Array &csv_block);

Thus, the call given above[file_array.grab(0).access(2,2); ]
actually has one additional class “level” in between and is more like

    csv_Analysis analysis_Object(file_array); 
    analysis_Object.grab(0).access(2,2); 

where grab acts in the same way, and is also defined as a member function of csv_Analysis class.

  • 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-23T09:20:48+00:00Added an answer on May 23, 2026 at 9:20 am

    You probably want to make grab return a reference rather than a copy:

    csv_File& grab(int index);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class in a Windows Service that is experiencing some vary
I'm experiencing something really strange! I have a div that I'm hiding with JS
Using the json module in python 2.6, I'm experiencing some unexpected behavior when passing
I am experiencing an unexpected value of errno when using perror with glibc .
I am experiencing a crash while using the Boost.Spirit and Boost.Thread libraries in my
Lately our customers are experiencing unexpected crashes. We are already logging the errors on
I have created a custom panel (MyCustomControl) that can contain other controls and be
Using PHP 5.3 I'm experiencing weird / non-intuitive behavior when applying empty() to dynamic
I'm experiencing unexpected compiler errors with this code: bool b = true; //or false
I am experiencing a weird behavior by Scala handling of superclass constructors. I have

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.