BinaryByter
but if possible, use cont over not-const
olli
Mark
rarely
abhi3700
When it is about performance, i think we should not choose 1), as it creates a copy.
abhi3700
For me actually, 3) makes more appropriate.
abhi3700
So, what do you suggest 2) as the best option.
abhi3700
?
Anonymous
the best one is 3), in this case how olli said it is useless
olli
consider this
extern void f0(int,int,int);
extern void f1(const int&,const int&,const int&);
calling f0(1,2,3) generates
mov edx, 3
mov esi, 2
mov edi, 1
call f0(int, int, int)
calling f1(1,2,3) generates
lea rdx, [rsp+12]
lea rsi, [rsp+8]
mov DWORD PTR [rsp+12], 3
lea rdi, [rsp+4]
mov DWORD PTR [rsp+8], 2
mov DWORD PTR [rsp+4], 1
call f1(int const&, int const&, int const&)
Anonymous
it depends on how compiler implements lvalue reference
abhi3700
consider this
extern void f0(int,int,int);
extern void f1(const int&,const int&,const int&);
calling f0(1,2,3) generates
mov edx, 3
mov esi, 2
mov edi, 1
call f0(int, int, int)
calling f1(1,2,3) generates
lea rdx, [rsp+12]
lea rsi, [rsp+8]
mov DWORD PTR [rsp+12], 3
lea rdi, [rsp+4]
mov DWORD PTR [rsp+8], 2
mov DWORD PTR [rsp+4], 1
call f1(int const&, int const&, int const&)
Ohk
abhi3700
👍👍
abhi3700
In int type, 1) is best.
olli
If func should not modify the paramters, use the first approach
abhi3700
But for object type arguments, 3) is best
olli
for non primitive types 3) might be a better choice (e.g. string, vector, ...)
abhi3700
Primitive types- e.g.. ??
olli
to complete the example above
int a = 1, b = 2, c = 3;
f0(a,b,c);
generates
mov edx, 3
mov esi, 2
mov edi, 1
jmp f0(int, int, int)
int a = 1, b = 2, c = 3;
f1(a,b,c);
generates
lea rdx, [rsp+12]
lea rsi, [rsp+8]
mov DWORD PTR [rsp+4], 1
lea rdi, [rsp+4]
mov DWORD PTR [rsp+8], 2
mov DWORD PTR [rsp+12], 3
call f1(int const&, int const&, int const&)
abhi3700
olli
or in other words, it doesn't really matter whether you take a reference to something or create a trivial copy if it does fit in a register
abhi3700
abhi3700
But, still I am not sure I have mastered it entirely.
abhi3700
What sources I can go through in order to master it.
abhi3700
@ollirz can u suggest some?
olli
@ollirz can u suggest some?
I think you have a decent understanding! If you are unsure either use const & or ask us (const & does not depend on the type and should always be equally fast)
Otherwise maybe read [1] and [2], Item 41 from Effective Modern C++ might be also a good read
[1] https://stackoverflow.com/questions/373419/whats-the-difference-between-passing-by-reference-vs-passing-by-value
[2] https://stackoverflow.com/questions/40185665/performance-cost-of-passing-by-value-vs-by-reference-or-by-pointer
BinaryByter
they might be
they are not useful in terms of efficiency*
Mark
https://0x0.st/sUVH.png
Mark
...
abhi3700
abhi3700
abhi3700
Anyone here has ever attended cppcon held every year?
Saurabh
If anyone has good stl c++ notes pdf please share with me
klimi
Saurabh
klimi
Saurabh
If you have pdf please share me personally
klimi
#freeprogrammingbooks
klimi
Saurabh
Yes
Mark
just google for some
Mark
it's not hard
klimi
I don't have mood for this
klimi
/saved
klimi
Read pinned msg
klimi
Everything you need
Mark
@rebane2001 don't click on that button
Mark
ur not a human
Mark
:^)
Rebane
why they have google recaptcha on c server
Avamander
Is that button supposed to work?
BinaryByter
it did work
BinaryByter
you have to click on it in order to write
Avamander
Okay, good UX right there.
Avamander
:D
BinaryByter
not mine 🤷♂
BinaryByter
BinaryByter
SEXISM
Mark
Rebane
We should delete telegram from internet
BinaryByter
i pronounce gif like 'yiff'.
BinaryByter
jk, i'm not from northern germany
Mark
>yiff not yiff you expected to be
Rebane
I pronounce it as yiff because that pisses mark off
BinaryByter
@ollirz ja jetzt jönnen wir uns doch eine reaktjionsjif
BinaryByter
only he will understand my allusion to northern germans :(
BinaryByter
maybe he will
BinaryByter
im too tired to be cool
Mark
great
BinaryByter
im always too tired no matter how mucd i sleep
Rebane
I'm not cool either way
Mark
BinaryByter
ima sleep
Mark
aight gn
BinaryByter
class test in maths tomorrow
BinaryByter
about quadratic formulaes