3 ms·
The right equivalent is actually punning through char* and enforcing lack of simultaneous aliasing. This is explicitly allowed in C++11. Memcpy is a cost. Do i
by AstralStorm 8y ago
The right equivalent is actually punning through char* and enforcing lack of simultaneous aliasing. This is explicitly allowed in C++11.
Memcpy is a cost. Do it only when you actually need a copy.
- saagarjha 8y agoAll half-decent compilers elide a memcpy when you're using it for this purpose; they'll just generate the assembly you "intended" to create. And while I know casting to a char * is legal for all types, I don't believe casting from a char * is legal unless the memory the pointer references is actually the type you're casting to. I'll have to check on this–or if you have a link to the standard on this I can just look at that.