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

small_vector cannot go back to use stack space #279

Closed
igaztanaga opened this issue May 21, 2024 · 1 comment
Closed

small_vector cannot go back to use stack space #279

igaztanaga opened this issue May 21, 2024 · 1 comment

Comments

@igaztanaga
Copy link
Member

igaztanaga commented May 21, 2024

As reported in:

https://stackoverflow.com/questions/54429138/boost-small-vector-cannot-go-back-to-use-stack-space

small vector does not go back to the internal storage even after shrink_to_fit. This behavior is explicitly documented for the class but maybe it should be revisited, specially for shrink_to_fit.

The LLVM implementation does not seem to offer this feature, Folly seems to implement construct + swap to achieve it in shrink_to_fit.

In the same line, in current swap implementation, when one vector uses a dynamic buffer and the other one the internal buffer, swap allocates also a dynamic buffer for the vector with the internal buffer. This should be avoided

@igaztanaga
Copy link
Member Author

The commit aa35950 finishes changes in small_vector so that:

  • shrink_to_fit migrates data to the internal buffer if size() <= internal_capacity().
  • swap acquires the existing dynamic buffer to avoid moving elements, and uses the internal buffer if the dynamic buffer can't be acquired and data fits in the internal buffer.

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