12 ms·
I'm not as familiar with how C++ does allocations compared to julia, but I'd imagine the limitations would be similar - if `new` can allocate memory on the stac
by Sukera 4y ago
I'm not as familiar with how C++ does allocations compared to julia, but I'd imagine the limitations would be similar - if `new` can allocate memory on the stack, I can't imagine why it wouldn't work out of the box.
C++ really isn't my forte though.
- pjmlp 4y agoWith placement new you can allocate wherever you want, as the memory region is one of the parameters. You can also overload it, so that it can be given as implicit parameter. Modern C++ compilers are also able to do escape analysis and remove new altogether, https://godbolt.org/z/f9vnxG88K https://godbolt.org/z/f9vnxG88K If you try AVR instead of X64, the optimization will be missing, which is only a side effect of the backend not having as much attention in what it looks into.
- londons_explore 4y agoIf you comment out the delete[] line, it returns the same output. Does that mean leaking memory is undefined behaviour?
- pjmlp 4y agoLeaking memory is always undefined behaviour regardless of the language when talking about manual memory management. What guarantees can you assure about the state of the application? In any case, in this specific example for x64 it doesn't matter, because new gets optimized away. However, if that optimization isn't done, e.g. AVR backend, then nasal daemons will be summoned.