> you can guarantee a piece of code will never trigger an allocation
I'd be interested to see an example of this, if possible, say, with an application of flatMap and filtering in a chain or something similar (or just
exDM69's example), without pre-scanning the collection.
I think C++ does really well when memory needs are known or can be bounded to something reasonable up front, but not as well as a good high performance GC when many temporary allocations need to be made where their size can't be known until runtime. I would love to be wrong about that though, the language has a lot going for it.
You can guarantee the heap will not be touched in any code that:
- does not use malloc or new
- does not call any function that uses malloc or new
When you do that, you make allocation decisions orthogonal to the algorithm. This is how all the std algorithms are implemented.
Haskell also separates allocation from algorithm, but it so by making decisions for the programmer -- by using GC. This is not an acceptable trade-off for a C++ developer or else she would be using a different language (or smart pointers).
> You can guarantee the heap will not be touched in any code
> that: - does not use malloc or new - does not call any
> function that uses malloc or new
Which is extremely limiting, in the context of data analysis chains like the examples given.
I'd be interested to see an example of this, if possible, say, with an application of flatMap and filtering in a chain or something similar (or just exDM69's example), without pre-scanning the collection.
I think C++ does really well when memory needs are known or can be bounded to something reasonable up front, but not as well as a good high performance GC when many temporary allocations need to be made where their size can't be known until runtime. I would love to be wrong about that though, the language has a lot going for it.