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

fixed_function is not that "fixed" sometimes #464

Open
Vuhdo opened this issue Mar 25, 2022 · 0 comments
Open

fixed_function is not that "fixed" sometimes #464

Vuhdo opened this issue Mar 25, 2022 · 0 comments

Comments

@Vuhdo
Copy link

Vuhdo commented Mar 25, 2022

Sometimes fixed_function actually allocates memory and that is quite unexpected and confusing.

The problem is due to alignment: when one of a captured lambda arguments has an alignment, instead of an in-place allocation it can allocate on the heap.

Here's more or less minimal example that I hope demonstrates the problem: https://godbolt.org/z/M6d4GrK3v
Here AlignedVec is aligned by 16 bytes, which makes the lambda capturing it also aligned and this does not pass the is_functor_inplace_allocatable check. And that one leads to a heap allocation.

My C++ template knowledge fails me here. Is there a way I could force fixed_function to use the inplace storage with aligned lambda captures? It would be really cool to make the class just work with any kind of aligned arguments.

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

1 participant