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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:10:04+00:00 2026-05-30T13:10:04+00:00

i have a project in c++03 that have a problem with data structure: i

  • 0

i have a project in c++03 that have a problem with data structure: i use vector instead of list even if i have to continuously pop_front-push_back. but for now it is ok because i need to rewrite too many code for now.

my approach is tuo have a buffer of last frame_size point always updated. so each frame i have to pop front and push back. (mayebe there is a name for this approach?)

so i use this code:

Point apoint;  // allocate new point
apoint.x = xx;
apoint.y = yy;

int size = points.size()
if (size > frame_size) {
    this->points.erase( points.begin() );  // pop_front
}
this->points.push_back(apoint);

i have some ready-to-use code for an object pool and so i thought: it is not a great optimization but i can store the front in the pool and so i can gain the allocation time of apoint.

ok this is not so useful and probably it make no sense but i ask just to educational curiosity: how can i do that?

how can i store the memory of erased element of a vector for reusing it? does this question make sense? if not, why?

.. because erase does not return the erased vector, it return:

A random access iterator pointing to the new location of the element
that followed the last element erased by the function call, which is
the vector end if the operation erased the last element in the
sequence.

  • 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-30T13:10:06+00:00Added an answer on May 30, 2026 at 1:10 pm

    i have some ready-to-use code for an object pool … how can i do that?

    Using a vector, you can’t. A vector stores its elements in a contiguous array, so they can’t be allocated one at a time, only in blocks of arbitrary size. Therefore, you can’t use an object pool as an allocator for std::vector.

    how can i store the memory of erased element of a vector for reusing it? does this question make sense? if not, why?

    The vector already does that. Your call to erase moves all the elements down into the space vacated by the first element, leaving an empty space at the end to push the new element into.

    As long as you use a vector, you can’t avoid moving all the elements when you erase the first; if that is too inefficient, then use a deque (or possibly a list) instead.

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

Sidebar

Related Questions

We have the problem that we have the open project files in our SVN
I'm using Entity Framework in my project, and I have the problem that, once
problem is that I have to checkout a different branch for every project. and
I have a project that I'm currently working on but it currently only supports
I have a project that I thought was going to be relatively easy, but
Problem: I have a symfony project with a database full of production data I
I have a simple Scala project that runs without any problems inside Eclipse, however,
I have project that I'm working on that is going to require a webserver.
I have a project that I would like to start beta testing soon, it
I have a project that I'm working on and I need to be able

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.