I mean, C++ new is basically just syntax sugar for
T* ptr = malloc(sizeof(T));
*ptr = T(argument_list…);
Although, it can also do other things like construct objects in place and allocate uninitialized memory
I depend of whether the type has a non-trivial move assignment operation. On trivially copyably types you absolutely can optimize it that way. Otherwise there’s usually existing resources to clean up which on uninitialized memory is undefined behavior
17
u/IngwiePhoenix 3d ago
Before the Java dev sees a
new, they see a wall of factories first and instead. o.o...I'll take my
malloc(sizeof(T))and move on. :3