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

Use butil::AlignedMemory instead of std::aligned_storage to align memory for placement new #2719

Merged
merged 1 commit into from
Sep 26, 2024

Conversation

chenBright
Copy link
Contributor

@chenBright chenBright commented Jul 30, 2024

What problem does this PR solve?

Issue Number: #2288 中引入用于对齐Element地址的std::aligned_storage在C++23中已经被废弃了。详细背景见P1413R3提案。

Problem Summary:

What is changed and the side effects?

Changed:

C++17起,使用P1413R3提案中建议的alignas(T) std::byte element_spaces[sizeof(T)]来代替std::aligned_storage

  1. butil::AlignedMemory的实现跟P1413R3提案中建议的alignas(T) std::byte[sizeof(T)]类似,优点是封装性更好,所以使用butil::ManualConstructor(包含butil::AlignedMemory)代替std::aligned_storage
  2. MPSCQueueNodeObjectPoolResourcePool也需要对齐。
  3. 补充了一下ALIGNAS宏的一些注释(来自于chromium)。

Side effects:

  • Performance effects(性能影响):

  • Breaking backward compatibility(向后兼容性):


Check List:

  • Please make sure your changes are compilable(请确保你的更改可以通过编译).
  • When providing us with a new feature, it is best to add related tests(如果你向我们增加一个新的功能, 请添加相关测试).
  • Please follow Contributor Covenant Code of Conduct.(请遵循贡献者准则).

@wwbmmm
Copy link
Contributor

wwbmmm commented Aug 8, 2024

LGTM

@chenBright chenBright force-pushed the deprecate_aligned_storage branch 8 times, most recently from bce74c5 to a617bec Compare August 11, 2024 06:09
@chenBright chenBright changed the title Use alignas std::byte instead of std::aligned_storage since C++ 17 Use butil::AlignedMemory instead of std::aligned_storage to align memory for placement new Aug 11, 2024
@chenBright
Copy link
Contributor Author

@wwbmmm 有空再看看

@wwbmmm
Copy link
Contributor

wwbmmm commented Aug 19, 2024

LGTM

@wwbmmm wwbmmm merged commit c727dd7 into apache:master Sep 26, 2024
20 checks passed
@chenBright chenBright deleted the deprecate_aligned_storage branch September 26, 2024 02:54
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