Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 09-05-2019, 14:36
chants chants is offline
VIP
 
Join Date: Jul 2016
Posts: 826
Rept. Given: 47
Rept. Rcvd 50 Times in 31 Posts
Thanks Given: 737
Thanks Rcvd at 1,140 Times in 529 Posts
chants Reputation: 51
Exactly right. The class you mention is originally known as a functor with the operator parenthesis.

And very notably though, lambdas are slightly more efficient. Because no class is truly constructed. The constructor you wrote is not actually called - it can be optimized out by the compiler. There is no constructor/destructor just copying capture values and invocation of the () method and of course the object is stack constructed not dynamically allocated.

A really thorough analysis is here:
Quote:
https://web.mst.edu/~nmjxv3/articles/lambdas.html
Useful conclusions:
Quote:
1. Functors and lambdas are always passed a this pointer, whereas plain functions naturally are not. This consumes an extra register and 8 bytes of stack space.
2. Lambda "constructors" are inlined into the function in which the lambda is created. This significantly reduces the amount of copying performed (2 instructions for lambdas, 5 for functors), as well as avoiding a function call setup and teardown.
Reply With Quote
The Following User Says Thank You to chants For This Useful Post:
zeffy (09-05-2019)
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT +8. The time now is 08:00.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( Since 1998 )