Skip to content

[C++] allocation free error Status #44491

Closed

Description

@bkietz

Describe the enhancement requested

In many situations, it'd be beneficial to have an error Status which was copyable without using the heap. For example, this is a frequent pain point with Result. We want Result to be default constructible even if T isn't, so a defaulted Result is an error but this requires heap allocating a Status::State which we immediately overwrite. Similarly, if the value or error is moved out of a Result we'd like to avoid managing the stored object and wind up heap allocating a flag.

Allowing some Status objects to have static lifetime (for example, by tagging the state_ pointer or adding bool Status::State::is_static) should not have an effect on the critical hot paths of moving a status or skipping deletion of ok status. Copying will get slightly slower since we need to branch on state_->is_static, but that's already quite slow due to heap interaction.

Component(s)

C++

Activity

  1. bkietz commented on Oct 21, 2024

    @bkietz
    MemberAuthor

    FWIW, absl::Status uses pointer tagging for its junk value: https://github.com/abseil/abseil-cpp/blob/master/absl/status/status.h#L901-L903

  2. added 2 commits that reference this issue on Nov 14, 2024
  3. pitrou commented on Nov 14, 2024

    @pitrou
    Member

    Issue resolved by pull request 44493
    #44493

  4. added this to the 19.0.0 milestone on Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions