Advanced Topics: Copy Elision
Вставка
- Опубліковано 15 січ 2020
- In this video we talk about copy elision and the return value optimization!
Arthur's Talk - • CppCon 2018: Arthur O'...
For code samples: github.com/coffeebeforearch
For live content: / coffeebeforearch - Наука та технологія
Awesome, I wish someone would teach a whole course of C++ with compiler explorer :).
I've been wanting to fo a "C++ for Compiler Explorers" for a while, doing similar type videos. So many ideas, so little time...
Note that the RVO can still apply even when the function has several return statements, as long as the returned objects are created on the return statements
hi nick thanks for the great material, if i may give you a little audio advice is to apply a lowcut/highpass filter to cut the bass from the audio i thought my neighbors were doing some noise because of the bass rumble , and we/you don't need the bass frequency content of the audio in your videos. thanks again for the great videos !
if you don't have copy elision, in the exaple with the struct, you won't be copying just a pointer to the array? What is it so awful to copy pointers? Or when it returns it copies a pointer to each chunk of 2 bytes (as the registers are). Thanks
You wouldn't want to copy a pointer because the memory is located on the stack, and goes out of scope when the function returns.
I didn't the initial part around 1:15. EAX and EDX are each 32bits and sizeof(int) is 32bits as well. So how can they store 4 ints that requires 128 bits and you have only 64 bits combined? You're confusing EAX and EDX with RAX and RDX?
It's making an optimization since the array is 0/default initialized, output is same for int data[4] = {1, 0, 1, 0}. Try int data[4] = {0, 0, 0, 1} or int data[4] = {0, 1, 0, 0}. Now rax and/or rdx must be utilized.