4 ms·
> Strictly speaking, in the C++ object model, malloc allocates storage but doesn't create objects. No - strictly speaking, it does create objects. https://en.c
by dataflow 1y ago
> Strictly speaking, in the C++ object model, malloc allocates storage but doesn't create objects.
No - strictly speaking, it does create objects. https://en.cppreference.com/w/cpp/memory/c/malloc.html#:~:text=implicitly%20creating%20objects%20in%20the%20destination%20area https://en.cppreference.com/w/cpp/memory/c/malloc.html#:~:te...
It gets confusing (to say the least) if you start questioning the details, but the spec does formally intend the objects to be implicitly created.
- jagged-chisel 1y agoI’m not a C++ dev … Does that mean calling constructors? So a default, parameter-less constructor must exist for the given type, and it will be called N times - right?
- dataflow 1y agoIt's only legal for types that are sufficiently trivial, so the "called constructor" would be trivial. You'll want to follow the links in the page I sent you, it's explained: https://en.cppreference.com/w/cpp/language/classes.html#Implicit-lifetime_class https://en.cppreference.com/w/cpp/language/classes.html#Impl...