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

Short string optimization using custom alocator #101

Open
dimztimz opened this issue Dec 9, 2020 · 0 comments
Open

Short string optimization using custom alocator #101

dimztimz opened this issue Dec 9, 2020 · 0 comments

Comments

@dimztimz
Copy link
Contributor

dimztimz commented Dec 9, 2020

Some standard containers have good SSO, like std::string, but others have bad like std::wstring, or some have none, like std::vector. We can make any contiguous container have SSO with custom allocator. With this we can replace global or, more precisely, thread-local objects at the places they are used, which we use to avoid lot of memory allocations by reusing the old buffers.

An example for such solution is:

A C++ allocator can not give memory from within the same object, thus the following is wrong https://github.com/HowardHinnant/HowardHinnant.github.io/blob/master/stack_alloc.h . Howard Hinnant first wrote the wrong one (stack_alloc.h) and then made the correct one (short_alloc.h).

Another solution is to use new features from C++ https://en.cppreference.com/w/cpp/memory/monotonic_buffer_resource . See a tutorial for that. These features are still not implemented in LLVM's libc++.

@dimztimz dimztimz added this to the Version 6 milestone Dec 9, 2020
@dimztimz dimztimz removed this from the Version 6 milestone May 12, 2022
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