Re:When zero cost abstractions aren't zero cost
by tialaramex on Monday August 09, 2021 @10:39PM
(#28124670)
Technically it postpones initializing the memory, and then it exits before that is needed.
If you actually use the memory, both cases work out the same. There are too many languages where you can easily make the mistake of reading uninitialized memory, and that can't happen here, if you ask to sum() the vector you'll get a zero answer in both cases... and both programs will be similarly slow.
Re:When zero cost abstractions aren't zero cost
by tialaramex on Monday August 09, 2021 @11:40PM
(#28124943)
(Note that you can't actually "sum" the code sample's wrapper type because it lacks the appropriate operations. I spent a while trying to actually make a working example where I trusted I was measuring something "real" and not artefacts and I eventually gave up. Definitely begin with an actual problem, so that you know what you're trying to do and can measure whether you're doing it or else you may just be wanking)
One version initializes the memory and the other one doesn't. There's a lot of subtle ways to cause that in different languages.