Aim: To understand the motivation why C++17 introduced std::aligned_alloc
for dynamic memory management.
Problem: For the memory allocation in C++, using std::malloc
is virtually always discouraged due to various reasons exemplified under In what cases do I use malloc and/or new?. Instead, using new
expression is almost always encouraged in low-level code (e.g. see Notes).
Despite this discouragement, I wonder why C++17 introduced std::aligned_alloc
which looks like a continuation of std::malloc
.
Is there anything in C++17 (and beyond) that cannot be performed by new
(or other equivalent utilities encouraged to use, if any)?
Attempts: I could only find the following discussion, which is still remotely related to my question: