HNHacker News
TopNewBestAskShowJobs

jfkrorkt

9 karma · joined August 21, 2020

submissionscomments
jfkrorkt··on But I was helping the compiler
You are right, the move is after the function returns (a copy). Thanks for pointing it out.

Btw, that's what I meant by statically allocated, I wasn't sure what's the proper terminology.

jfkrorkt··on But I was helping the compiler
On the other hand, it's basically impossible to write in C something as fast as Eigen, because it's exactly the compiler that gets into your face which can optimize away the intermediate layers of abstractions, in a way that would require 10 times the amount of code in C.
jfkrorkt··on But I was helping the compiler
Am I right to say that using std::move is even a logical mistake here?

The purpose of move is to "steal" the underlying memory, but if you do that, you leave the gfx variable from the class without backing. So basically you would need to reallocate it after every call to get_display_pixels. So the code only works because the author uses array, which is statically allocated and there is nothing to steal. It would break were they to switch to vector.

Either the author doesn't understand what the purpose of move is, or if this is really their intent, it's a terrible design, since get_display_pixels looks like an idempotent getter function, but it's not.