3 ms·
C++'s new operator can also do this using "placement new" semantics[1], which usually means making (and using) a custom allocator. You're still using the norma
by seanhunter 3y ago
C++'s new operator can also do this using "placement new" semantics[1], which usually means making (and using) a custom allocator. You're still using the normal new operator, just passing extra parameters to do the placement you want.
To your second point about raw speed, one of the extraordinary things we found in long-running processes performing computation using real-time marketdata at Goldman was that the HotSpot JVM was able to optimize java programs through the day due to their usage, so if you started them each day they would actually end up faster than the C++ versions at the end of the day even though they would start off slower. That's not due to memory allocation it's due to things like inlining of functions.
The implication of that is that if you very carefully inlined all the functions appropriately in the C++ version based on profiling actual usage you would be able to achieve the same result, but for the JVM it just happens automatically without you doing anything.
[1] Search https://en.cppreference.com/w/cpp/language/new https://en.cppreference.com/w/cpp/language/new for "Placement New"