New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add StaticDeque #4658
Add StaticDeque #4658
Conversation
Hi Will, |
Yeah, probably should have mentioned that somewhere. It's to store the past values for multistep time steppers. The usage pattern makes this naturally a deque, and knowing what time steppers we have we know the queue will never have more than 8 elements. I'm pretty sure libstdc++'s implementation of I think libc++'s implementation is actually smart enough to keep and reuse its storage blocks, so it would be fine for the main history. It's not clear whether the initial allocation of space would be significant in the IMEX code, which creates a temporary This idea was also mentioned in passing in some unrelated recent PR, but I don't remember which or how useful it would actually have been there. |
Ah, I think @kidder used a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, a couple requests for a bit more C++ comments that I think would make it clearer to readers in the future. Please squash them in directly :)
p | sz; | ||
resize(sz); | ||
for (auto& entry : *this) { | ||
p | entry; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we end up with this class holding a fundamental types (I currently don't see that we would get that a lot), then we would want this to use PUP_array
that serializes a byte stream directly (might be more efficient). I don't think that's important now, but just want to mention it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For fundamentals (and I think any trivially copyable types), I'm pretty sure we can just serialize the byte stream and the other member variables and restore the exact state. For more complicated things, we have to be careful not to try to pup the unused memory as objects of type T, so the current version just accesses the objects through the public interface and doesn't try to restore the details of the internal representation. (The elements may be "rotated" in the internal circular buffer after deserializing.) Switching to the first implementation when allowed would certainly be possible, but let's put it off for now. I've added a comment summarizing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you! Thanks for adding the nice comment!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have expanded the comment explaining the meaning of the member variables and the logical treatment of the storage, and added some short comments for the other things.
p | sz; | ||
resize(sz); | ||
for (auto& entry : *this) { | ||
p | entry; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For fundamentals (and I think any trivially copyable types), I'm pretty sure we can just serialize the byte stream and the other member variables and restore the exact state. For more complicated things, we have to be careful not to try to pup the unused memory as objects of type T, so the current version just accesses the objects through the public interface and doesn't try to restore the details of the internal representation. (The elements may be "rotated" in the internal circular buffer after deserializing.) Switching to the first implementation when allowed would certainly be possible, but let's put it off for now. I've added a comment summarizing this.
p | sz; | ||
resize(sz); | ||
for (auto& entry : *this) { | ||
p | entry; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you! Thanks for adding the nice comment!
Proposed changes
Upgrade instructions
Code review checklist
make doc
to generate the documentation locally intoBUILD_DIR/docs/html
.Then open
index.html
.code review guide.
bugfix
ornew feature
if appropriate.Further comments