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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:59:11+00:00 2026-05-30T05:59:11+00:00

This is my first time using stackoverflow for a question, I have read a

  • 0

This is my first time using stackoverflow for a question, I have read a few answers previously which have helped me in some cases so I thought I’d register seeing as I can’t find the specific answer I’m looking for. Recently I made a pretty simple particles system that spews out a couple 100 to 1000s of particles just to see if I could do it, before I even started this I made a simple Linked List which uses templates so I can use it in other programs if I so choose.

Recently, after seeing a colleague of mine playing about with a particle system he found I decided to revisit my project to improve upon it. I scoured the internet to find a little example which apparently ditches the idea of using a Linked List and instead uses and array and three pointers to manage the particles. I understand most of the concept but for some reason one thing escapes me.

 /// the first particle in the linked list
    Particle* start=0;

/// the next free particle
Particle* last=0;

/// the end of the memory allocation
Particle* end=0;

void SetSize(unsigned int size) {

    // delete any previous data
    delete [] start;

    // allocate new particles 
    last = start = new Particle[size];

    // set end
    end = start+size;
}

void AddOne() {

    // if we have no more memory left for any particles, ignore
    // the request to creat one.
    if (!IsFull()) {
        *last = Particle();
        ++last;
    }

}

void EraseOne(Particle* p) {

    if (!IsEmpty()) {
        *p = *(--last);
    }

}

From what I understand from the code above the three pointers act as simple pointers to the elements in the array. The start pointer remains at zero and the end pointer remains at the end of the array while last starts from the same position as the start pointer and moves along like an index counter until it gets to the end.

What I’m unsure of is the erasing bit, I assume from the code above that ‘p’ is becoming not the particle the last pointer is pointing to but the one before last. Unfortunately I have no idea why it is done this way as surely the one before last is a perfectly alive particle but wouldn’t this make two instances of the same particle?

  • 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-30T05:59:12+00:00Added an answer on May 30, 2026 at 5:59 am

    The first thing is that you should use a standard continer rather than trying a half baked manual implementation. Now to the interpretation of the code:

    The code shows a common pattern. Basically you use three pointers, one to the beginning of the allocated memory, (equivalent to begin()), a pointer one beyond the last element (equivalent to end() and a third pointer one beyond the last allocated block (to avoid overflowing.

    With that in mind interpreting the functions is not hard. In particular, AddOne (similar to push_back but without growing the buffer) updates the first element beyond the end, and increments the pointer to refer to one beyond the new last element.

    As of EraseOne basically performs the reverse operation: it first decrements the pointer (so now the previouslast element is outside of the valid range) and then copies that element (remember that the pointer refers to one beyond the end)

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

Sidebar

Related Questions

This is my first time using StackOverflow myself. I have found many answers to
this is my first time posting here, I have a question which I have
This is my first time on StackOverflow though I read Coding Horror quite often.
This is the first time I am posting a question on stackoverflow, so please
This is my first time using stackoverflow. I've been unable to find out the
This is my first time using joomla. I don't know if I'm using the
this is my first time using StAX for parsing XML documents (still in the
I'm fairly new to both Django and Python. This is my first time using
This is the first time ever I'm using AJAX, and I want to do
I'm using this XML classes for the first time and can't find this piece

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.