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

Improve example solution of circular-buffer #1724

Merged
merged 1 commit into from
Sep 15, 2023
Merged

Commits on Sep 14, 2023

  1. Improve example solution of circular-buffer

    The trait bounds `Default + Clone` are semantically incorrect.
    A proper circular buffer needs to handle all kinds of elements.
    
    The reason these bounds are here is because it allows to avoid `unsafe`
    while enjoying the most efficient memory layout.
    However, there is another performance downside:
    The implementations of `Default` and `Clone` may be expensive
    (e.g. cause heap allocations.)
    
    As came up in this discussion, there are other weird side effects,
    for example for `Rc` which has a non-standard implementation of `Clone`:
    #1652
    
    The approach I chose here get's rid of the trait bounds and wraps
    every element in an `Option`.
    In the worst case, this may lead to twice the memory consumption.
    (e.g. `Option<u64>` takes 16 bytes because of alignment)
    This approach is semantically correct, but not the most performant.
    
    The most performant solution would be to use `unsafe`.
    I'd like to avoid that in example solutions.
    senekor committed Sep 14, 2023
    Configuration menu
    Copy the full SHA
    d3ed68a View commit details
    Browse the repository at this point in the history