Skip to content
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

flow: Add noexcept to move ctors (at least); including to avoid copying in vector (at least). #76

Open
ygoldfeld opened this issue Mar 10, 2024 · 0 comments
Labels
bug Something isn't working from-akamai-pre-open Issue origin is Akamai, before opening source

Comments

@ygoldfeld
Copy link
Contributor

Filed by @ygoldfeld pre-open-source:

Probably all move ctors here – but also look at ipc – should be noexcept. Also look at noexcept in general and see what prophylactic moves would be good. I am not super familiar with the topic.

What triggered this:

I made a vector and noticed that when it needs to re-alloc, for example due to an emplace_back(), gcc-8 (at least) starts copying Blobs around, even though Blob has a move ctor. So I looked into it, and - long story short -

vector<>, in both practice and theory (the standard, cppreference), will use move ctor exclusively, if and only if:

  • there is no copy ctor (such as with unique_ptr) in the stored type T
  • the move ctor is noexcept.

I could go on and post link, but that's the basic situation.

P.S. It's still a perfectly reasonable tactic to store vector<unique_ptr> if one wants guaranteed quickness in this sense. And I do that in Flow-IPC et al where I need it. So the above is more of a general change that is required medium/long-term, since Flow is a lib (EDIT: and now open-source).

@ygoldfeld ygoldfeld added bug Something isn't working from-akamai-pre-open Issue origin is Akamai, before opening source labels Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working from-akamai-pre-open Issue origin is Akamai, before opening source
Projects
None yet
Development

No branches or pull requests

1 participant