Skip to content

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.

1 points

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.

1 points

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?

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.