Why did C++17 introduce std::aligned_alloc?
Asked Answered
C

1

5

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:

Difference between aligned malloc and standard malloc?

Canterbury answered 13/9, 2020 at 14:16 Comment(0)
T
9

C++17 bumped up its support for plain C from C99 to C11. It inherited aligned_alloc along with other stuff from C11.

paper: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0063r3.html

So the motivation is to make C features available in C++ for those who want them.

Tingle answered 13/9, 2020 at 14:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.