I don't understand why you are storing pointers to placement-newed particles instead of just using the value type in the array itself. That'd solve the issues of update order (as you are always updating in order, the next particle is nearly guaranteed to be in cache) as well as simplifying the rest of the code.
Deleting might be a bit more expensive due to the larger amount of memory being swapped (if we are truly talking 130 bytes per particle...) , but I'm not convinced that it's a huge difference.
If you do the deletions in a separate loop beforehand it's effectively just a memcpy, and furthermore it'll be likely to increase the update performance as it'll avoid the possibility of branch mispredicts as well as simplifying the code, more easily allowing the compiler to utilise SIMD instructions or unroll the loop.
The pointers bit is solved in the last solution mentioned in my post.
Somewhere else someone said that if we swap the particles around with a memcpy then we can get rid of the holes in the buffer. That indeed sounds like a better solution than what we're doing with the ring buffer.
My reason to use placement new by the way is that I like to use constructors and this allows doing that.
That's not my point about placement new; the question is, why use a std::vector<Particle*> and placement new into a separate array (which incurs a pointless pointer follow per particle update, doesn't keep a consistent order as particles are deleted, takes more memory as you need to store the pointers, and requires extra bookkeeping for when the underlying array is full) instead of just using std::vector<Particle> directly?
4 comments
I don't understand why you are storing pointers to placement-newed particles instead of just using the value type in the array itself. That'd solve the issues of update order (as you are always updating in order, the next particle is nearly guaranteed to be in cache) as well as simplifying the rest of the code.
Deleting might be a bit more expensive due to the larger amount of memory being swapped (if we are truly talking 130 bytes per particle...) , but I'm not convinced that it's a huge difference.
If you do the deletions in a separate loop beforehand it's effectively just a memcpy, and furthermore it'll be likely to increase the update performance as it'll avoid the possibility of branch mispredicts as well as simplifying the code, more easily allowing the compiler to utilise SIMD instructions or unroll the loop.
The pointers bit is solved in the last solution mentioned in my post.
Somewhere else someone said that if we swap the particles around with a memcpy then we can get rid of the holes in the buffer. That indeed sounds like a better solution than what we're doing with the ring buffer.
My reason to use placement new by the way is that I like to use constructors and this allows doing that.
That's not my point about placement new; the question is, why use a std::vector<Particle*> and placement new into a separate array (which incurs a pointless pointer follow per particle update, doesn't keep a consistent order as particles are deleted, takes more memory as you need to store the pointers, and requires extra bookkeeping for when the underlying array is full) instead of just using std::vector<Particle> directly?