2

The clang docs cited in an answer to this SO question state

that the C++ standard does not permit [...] removing new / delete pairs and merging allocations

as optimizations.

Why is that?

nada
  • 2,109
  • 2
  • 16
  • 23
  • 1
    I'm pretty sure the c++ standard does allow this and clang certainly performs such optimizations. However, I believe it wasn't always the case, so maybe it is onlyu relevant in c++03 mode. – MikeMB Oct 15 '19 at 10:19
  • Relevant: [Is the compiler allowed to optimize out heap memory allocations?](https://stackoverflow.com/q/31873616/580083). – Daniel Langr Oct 15 '19 at 10:23
  • https://stackoverflow.com/a/31875487/560648 is the answer you want – Lightness Races in Orbit Oct 15 '19 at 10:24
  • @LightnessRacesinOrbit Yes you are correct plus clang could update its docs. It's in the standard since C++14 apparently. – nada Oct 15 '19 at 10:29
  • 1
    See also here: https://stackoverflow.com/questions/34590885/optimization-of-raw-new-delete-vs-stdvector (Where the Standard is actually quoted in the answer!) – Adrian Mole Oct 15 '19 at 10:30

0 Answers0