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

Allocator redesign #38

Conversation

ben-craig-cs
Copy link
Contributor

Switch to an allocator model similar to the STL. This required updating List, Vector, and SharedPtr, the current allocator clients.

Users of allocators should generally indirect their operations through AllocTraits. This allows user-provided allocators to provide a minimal set of basis operations (AllocBytes + FreeBytes, or Alloc + Free), while letting the remainder of the operations to be given sane defaults. This PR's approach to allocators deviates from the STL, in that allocator types aren't required to be templated on the value type. This makes allocator implementations more approachable, avoids the need to rebind, and can even help build throughput due to fewer template instantiations.

This PR also provides StdAllocator, a radiant allocator that forwards to std::allocator. This both provides an example of an allocator with all the features turned on, as well as provide the path to constexpr containers, if we want to go down that path. There are multiple test allocators (like Mallocator) that demonstrate the minimal interface.

There are some drive-by fixes / changes to List and Vector. There were missing self-assignment / self-splicing checks before hand. Vector also didn't have a move ctor, but did have an allocator move ctor. Also I fixed one of the many FalseTypes.

Useful background reading on implementing allocators: https://thephd.dev/allocator-hell-small_bit_vector .

Switch to an allocator model similar to the STL. This required
updating List, Vector, and SharedPtr, the current allocator clients.

Users of allocators should generally indirect their operations
through AllocTraits. This allows user-provided allocators to provide
a minimal set of basis operations (AllocBytes + FreeBytes, or Alloc +
Free), while letting the remainder of the operations to be given sane
defaults. This PR's approach to allocators deviates from the STL, in
that allocator types aren't required to be templated on the value
type. This makes allocator implementations more approachable, avoids
the need to rebind, and can even help build throughput due to fewer
template instantiations.

This PR also provides StdAllocator, a radiant allocator that forwards
to std::allocator. This both provides an example of an allocator with
all the features turned on, as well as provide the path to constexpr
containers, if we want to go down that path. There are multiple test
allocators (like Mallocator) that demonstrate the minimal interface.

There are some drive-by fixes / changes to List and Vector. There
were missing self-assignment / self-splicing checks before hand.
Vector also didn't have a move ctor, but did have an allocator move
ctor. Also I fixed one of the many FalseTypes.

Useful background reading on implementing allocators:
https://thephd.dev/allocator-hell-small_bit_vector .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant