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 #37

Merged
merged 3 commits into from
Jan 16, 2025
Merged

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 .
Copy link

codecov bot commented Jan 10, 2025

Codecov Report

Attention: Patch coverage is 82.32044% with 32 lines in your changes missing coverage. Please review.

Project coverage is 90.35%. Comparing base (da9ddc1) to head (2d14b0b).

Files with missing lines Patch % Lines
radiant/List.h 44.11% 12 Missing and 7 partials ⚠️
radiant/Memory.h 94.84% 0 Missing and 5 partials ⚠️
radiant/detail/VectorOperations.h 81.81% 0 Missing and 4 partials ⚠️
radiant/Vector.h 86.36% 0 Missing and 3 partials ⚠️
radiant/SharedPtr.h 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #37      +/-   ##
==========================================
- Coverage   90.85%   90.35%   -0.51%     
==========================================
  Files          19       20       +1     
  Lines        2603     2747     +144     
  Branches      312      326      +14     
==========================================
+ Hits         2365     2482     +117     
- Misses         17       31      +14     
- Partials      221      234      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jxy-s

This comment was marked as outdated.

@jxy-s jxy-s merged commit 79b2af3 into archonitelabs:main Jan 16, 2025
8 of 9 checks passed
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.

2 participants