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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:13:11+00:00 2026-06-07T01:13:11+00:00

I’m currently in the process of changing the way I access my data structures,

  • 0

I’m currently in the process of changing the way I access my data structures, and I’m reviewing one of two solutions in the general case for vectors of vectors.

My incentive is simple; I want cache locality without giving up my interfaces.

I know the max-size of my vectors at compile time, but they won’t always be reaching the max. Common case is about 80%, and the total size of each vector is to be relatively small.
If I reach that max, I have made an error in logic somewhere, and want it to throw an error.

The first solution that came to mind, was to use a Pool allocator with std::vector, seemed like a good idea, but maybe a bit messy; having not used allocators properly before, I wasn’t too sure of the solution. I’m not much of a fan for storing the data separate to its owners, and I want the implementation to be as transparent as possible.

The second solution works great for me at the moment, but I want to make it a little bit less in line. At the moment, it is thus:

class Foo {
public:
        std::array<Bar, 10> bars;
        size_t used;

        // std::vector<Bar> bars; // reserved to 10... maybe

        void add(int var1, int var2) {
                if (used >= bars.size()) throw "Error";
                bars[used] = Bar(var1, var2);
                ++used;

                // std::vector alternative
                // bars.push_back(Bar(var1, var2));
        }
        void remove(size_t idx) {
                bars[idx] = bars.back();
                --used;

                // bars.back().~Bar(); // should happen, not sure if safe

                // std::vector alternative
                // bars[idx] = bars.back();
                // bars.pop_back();
        }
}

Which, as mentioned, works great. However, if I wanted to move this solution elsewhere, I’d rather not have to implement it again, and have proper semantics in terms of destruction (similar to that of an actual vector).

So, I was wondering what a good solution could be? Currently, I’ve started wrapping an std::array, but it is starting to get messy, and I’m sure this is solved problem.

  • 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-07T01:13:14+00:00Added an answer on June 7, 2026 at 1:13 am

    See this link for several options for fixed-size data structures with a vector-like interface. In particular, boost::auto_buffer and eastl::fixed_vector seem viable options for your code.

    Yet another alternative is to use Hinnant’s stack allocator with the regular std::vector, but MSVC++ has some trouble compiling it.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I want to construct a data frame in an Rcpp function, but when I
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6

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.