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

ftl::TaskScheduler allocator support #76

Open
cwfitzgerald opened this issue Nov 15, 2018 · 7 comments
Open

ftl::TaskScheduler allocator support #76

cwfitzgerald opened this issue Nov 15, 2018 · 7 comments

Comments

@cwfitzgerald
Copy link
Contributor

As we start to allocate more and more with various improvements, we need a way of getting an allocator in there. My ideal would be to use std::polymorphic_allocator<byte> + std::memory_resource but that's c++17. Then our options are to reimplement memory_resource etc. in abseil style (there is a boost license c++11 impl of both), or to embed the allocator into the type. As a task scheduler is basically a global, embedding it in the type isn't the end of the world but would also require everything to be in the header which is less than ideal.

@RichieSams
Copy link
Owner

I haven't read into polymorphic_allocator or memory_resource much, but they both look much better than the default std allocators. When I was first creating this library, I was looking at EASTL, due to the pain of std allocators.

With polymorphic_allocator, can this be used with std containers? Or would we need to replace the containers with something else?

@RichieSams
Copy link
Owner

A simpler, albeit less elegant, solution would be a C-style allocation callback.

@cwfitzgerald
Copy link
Contributor Author

cwfitzgerald commented Nov 16, 2018

The standard solution is to use std::pmr::vector etc. which are just aliases for std::vector<T, std::pmr::polymorphic_allocator<T>> and so on. It truly is the solution to the C++ allocator nonsense. The std::pmr::polymorphic_allocator accepts a std::pmr::memory_resource* which does the allocation through its protected virtual do_allocate, do_deallocate and do_is_equal. Override those 3, you have full polymorphic allocation, i.e. per object non-typed differences in allocation strategy.

The C++11 impl is here, provided by the guy who gave the talk that made me understand it: here (1hr). If you do want to adopt it (my preference), I would definitely recommend going the abseil strategy of just aliasing the actual type if it is available.

C callback would work, wouldn't particularly make me happy tho 😄 .

@RichieSams
Copy link
Owner

I'm working on a first attempt this weekend.

@cwfitzgerald
Copy link
Contributor Author

cwfitzgerald commented Nov 17, 2018 via email

@RichieSams
Copy link
Owner

Yea. I'm using his C++11 impl of pmr. I'll have to figure out the best way to switch to the c++17 one if that's available

@cwfitzgerald
Copy link
Contributor Author

cwfitzgerald commented Nov 17, 2018 via email

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

No branches or pull requests

2 participants