Skip to content

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

Open
@ygoldfeld

Description

@ygoldfeld

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfrom-akamai-pre-openIssue origin is Akamai, before opening source

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions