Skip to content

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

Merged
wwbmmm merged 1 commit into
apache:masterfrom
chenBright:deprecate_aligned_storage
Sep 26, 2024
Merged

Use butil::AlignedMemory instead of std::aligned_storage to align memory for placement new #2719
wwbmmm merged 1 commit into
apache:masterfrom
chenBright:deprecate_aligned_storage

Conversation

@chenBright

@chenBright chenBright commented Jul 30, 2024

Copy link
Copy Markdown
Contributor

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

wwbmmm commented Aug 8, 2024

Copy link
Copy Markdown
Contributor

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 force-pushed the deprecate_aligned_storage branch from a617bec to eb86386 Compare August 11, 2024 06:13
@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
Copy Markdown
Contributor Author

@wwbmmm 有空再看看

@wwbmmm

wwbmmm commented Aug 19, 2024

Copy link
Copy Markdown
Contributor

LGTM

@wwbmmm wwbmmm merged commit c727dd7 into apache:master Sep 26, 2024
@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