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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:15:28+00:00 2026-05-29T04:15:28+00:00

Edit: The below question was answered by this . I have a new updated

  • 0

Edit: The below question was answered by this. I have a new updated question, is it any more efficient to use: (my friend said it is inefficient to put a vector of a vector because it uses sequential memory and to realloc when you push_back means it takes more time to find the location where a chunk of memory for the entire large vector can be placed)

(where Picture is a vector of lines, Line is a vector of points)

std::vector<Point> *LineVec;
std::vector<Line> PictureVec;

versus

std::vector<Point> LineVec;
std::vector<Line> PictureVec;


struct Point{
    int x;
    int y;
}

I’m trying to get a vector of a vector and my friend told me that it’s inefficient to put a vector of a vector because it uses sequential memory and vector of a vector will require huge amounts of space. So what he suggested was a using a vector of a pointer vector. Therefore the inner vector looks like this. Clearly I’m very new to C++ and would appreciate any insight.

struct Shape{
    int c;
    int d;
}
std::vector<Shape> *intvec;

When I want to push back into this, how would I do so? Something like this?

Shape s;
s.c=1;
s.d=1;
intvec->push_back(s);

Also, I wrote an iterator to go through, however it does not seem to work, hence why I believe the above code does not work. Finally my last concern is, while the above code works, it gives really weird values for my output. Large numbers that are 7 digits long and definitely not the values I put in for s.c and s.d

for(std::vector<Shape>::iterator it=Shapes->begin();it<Shapes->end();it++){
    Shape s = (*it);
    std::cout << s.c << s.d << std::endl;
}
  • 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-29T04:15:28+00:00Added an answer on May 29, 2026 at 4:15 am

    Using a vector of pointers to vectors is not more efficient than a vector of vectors. It’s less efficient, because it introduces an extra level of indirection. It also does not cause all elements of the resulting 2-d array to be allocated contiguously.

    The reason is that a vector is practically a pointer to an array, in the sense that a vector<T> is implemented roughly as

     template <typename T>
     class vector
     {
         T *p;  // pointer to array of elements
         size_t nelems, capacity;
    
       public:
         // interface
     };
    

    so that a vector of vectors behaves, performance-wise, like a dynamic array of pointers to arrays.

    [Note: I can’t quote the C++ standard chapter and verse, but I’m pretty sure it constrains std::vector‘s operations and complexity in such a way that the above is the only practical way of implementing it.]

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

Sidebar

Related Questions

Edit: Answered my own question. See below. -_- I have a variable defined in
EDIT ~ I have answered my own question below in the EDIT section, not
Edit: original question below, but I revise it now that I have some code
SEE EDIT UPDATES BELOW. Original question has been modified! I have a working window
Edit: Below is my working code based on the feedback/answers I recieved. This question
Read the edit below for more information. I have some code below that I
PLEASE SEE THE EDIT BELOW, THE REPORT SEEMS TO USE CACHED DATA? I cant
Answer solved in edit below I had this piece of code Dictionary<Merchant, int> remaingCards
I have a Controller with two Edit methods (see below). When I submit the
edit: my table schema below is poorly normalized as suggested and I have revamped

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.