Skip to content

Revamp buffer providers #188

@Morwenn

Description

@Morwenn

Currently the user-facing buffer providers suffer from poor decisions from the early days: they default-construct a buffer of elements, then the algorithms using buffer providers move elements to those. This design has a few issues:

  • Buffered sorters don't work with elements that are not default-constructible.
  • When the types are default-constructible but the operation is not trivial, we pay the cost of default construction for every element of the buffer, no matter whether it ends up being used or not.
  • Building a compatible buffer provider that allows default-constructible types would incur some additional overhead (see Add a buffer type for non-default-constructible types #59).

I think that the right solution is to let the buffer providers allocate the storage for enough elements, but the buffered sorters should construct and destroy the elements in the buffer as needed instead of just performing moves. This would definitely be a breaking change, so it's not something to do on the branch 1.x, but rather something to plan for 2.0.0.

The new design makes the new buffer providers look awfully like allocators, but a few design differences might make them too difficult to use properly with allocators, so I don't really want to merge them unless there is a well-motivated demand for it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions