为什么C ++ 17引入std :: aligned_alloc?

问题描述

目标:了解动机,为什么C ++ 17引入std::aligned_alloc用于动态内存管理。

问题:对于C ++中的内存分配,由于In what cases do I use malloc and/or new?中列举的各种原因,实际上始终不鼓励使用std::malloc。相反,几乎总是鼓励在低级代码中使用new表达式(例如,参见Notes)。

尽管有这种沮丧,我想知道为什么C ++ 17引入了std::aligned_alloc,看起来像是std::malloc的延续。

在C ++ 17(及更高版本)中,new(或鼓励使用的其他等效实用程序,如果有)不能执行任何操作吗?

尝试:我只能找到以下仍与我的问题密切相关的讨论:

Difference between aligned malloc and standard malloc?

解决方法

C ++ 17将对纯C的支持从C99扩展到C11。它继承了aligned_alloc和C11的其他内容。

论文:enter image description here

所以这样做的动机是使C功能可以供想要使用C语言的人使用。