|
|
|
|
|
by Nelson69
6141 days ago
|
|
The original article was terrible, so normally I wouldn't comment but I'll attempt to improve the discussion.. Do applications in C++ get modeled the same way as they would in Java or C#? Allocation speed doesn't quite seem like an apples to apples comparison. |
|
For example: Creating a temporary file and after some work deleting it would be done using try & finally sections in idiomatic Java, but in C++ an object would be used where the constructor contains the file creation and the destructor contains the deletion. This way the file lifetime is tied strictly to the object lifetime, which would be destroyed automatically when the code block is left.
However, the fact that object allocation on the heap is slow is mitigated by having the ability to create objects on the stack, which is probably even faster than Java or C#. And they are also managed automatically, so stack objects are always preferred if they are suitable.
While I think it is an apple-to-apple comparison, it is a microbenchmark, and as such probably irrelevant in most of the real-world cases.