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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:53:41+00:00 2026-05-15T16:53:41+00:00

I was wondering if it was faster to have a std::vector<std::vector<double>> where the nested

  • 0

I was wondering if it was faster to have a std::vector<std::vector<double>>where the nested vector always has 2 elements, or is it faster to have a std::vector<MyPoint>where MyPoint is defined like:

struct MyPoint {
  double Point[2];
};

Thanks

  • 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-15T16:53:42+00:00Added an answer on May 15, 2026 at 4:53 pm

    The vector<MyPoint> is preferable, because MyPoint is likely:

    1. to be smaller than vector<double> (you can check this with sizeof), and/or
    2. to make fewer allocations. A vector object itself is small, but generally points to data on the heap. It’s possible for small vectors to be optimised to avoid the extra allocation by embedding the data in the vector object, but don’t count on that, hence
    3. to have lower overhead of initialization, destruction, and copying.

    For example on my 32bit gcc, std::vector<double> has size 12, while MyPoint has size 16, but the vector makes the extra allocation. On a 64bit implementation, MyPoint will almost certainly be the same size, but std::vector will probably be bigger.

    Also, a vector represents a variable-sized, ordered container using contiguous memory. So it’s arguably overkill for a size-2 array, since the use of a vector introduces the possibility that the size might change.

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

Sidebar

Related Questions

Just wondering weather its faster, if you have lots (~several hundred to a thousand)
Just wondering which is faster: DELETE FROM table_name WHERE X='1' DELETE FROM table_name WHERE
I was wondering if it which is faster when trying to, for example, check
I've been wondering this for some time. As the title say, which is faster,
Wondering if anyone has gotten the infamous database is locked error from Trac and
Wondering if anybody out there has any success in using the JDEdwards XMLInterop functionality.
Wondering how to open many new windows with Javascript. I have found plenty of
How large does a collection have to be for std::map to outpace a sorted
I was wondering if it was ever ok not to have a submit button
I have made the experience that editing large XAML files is extremly faster when

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.