c++ - examples for move constructor/assignment operator that effect correctness? -


i wandering if there examples not implementing move semantics (i.e., move constructor , move assignment operator) effect correctness of program , not performance.

this value type implementing copy semantics 1 (or more) of following:

  • irrational (aka: antithetical design of class)

  • impossible

  • incurs cost can lead program termination/deadlocking

the "irrational" category types unique_ptr, logical design of type makes copying nonsensical.

the "impossible" category include wrapper types many apis exist outside of system.

consider wrapper type opengl object. might think that, because opengl query-able api (you can query every piece of state set it) reasonably implement object copying getting state old object , setting in new one.

but flawed because of opengl extensions. can give objects new state, code written before extensions know nothing about.

the final category sounds odd. let's take opengl wrapper idea. let's implement copying. , you're copying buffer object (a section of gpu memory).

well... doing copying? doing on thread has opengl context current? object being updated simultaneously in thread, such you've somewhere else, such you've created race condition?

you try use mutexes avoid race condition, you've created real possibility of deadlocking. why? because many objects contain buffer objects. , copying objects naturally need copy containing buffers. have multi-copy operation has lock multiple mutexes job. can deadlock against other multi-copy operation, if they're copying same buffers.

so either take chance on deadlocking, take chance on getting inconsistent memory copies... or don't allow copying @ all.

and if type doesn't allow copying, unless type's design says otherwise, ought allow moving.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -