tag:blogger.com,1999:blog-8755629231838247325.post5864275406969159112..comments2023-03-05T08:00:30.601-08:00Comments on random thoughts: Deferred function call in C++finalpatchhttp://www.blogger.com/profile/00977023159563294844noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-8755629231838247325.post-51695861157235942062015-06-13T20:20:12.495-07:002015-06-13T20:20:12.495-07:00First off, stateless lambdas do not trigger heap a...First off, stateless lambdas do not trigger heap allocations when placed in std::functions, at least under clang, and probably by now in gcc as well: http://stackoverflow.com/questions/12452022/g-stdfunction-intialized-with-closure-type-always-uses-heap-allocation. <br /><br />Also, I don't see why your problem can't be better solved by using std::function with a custom allocator/memory pool: http://stackoverflow.com/questions/21094052/how-can-i-create-a-stdfunction-with-a-custom-allocator.Nirhttps://www.blogger.com/profile/05489961144403356771noreply@blogger.comtag:blogger.com,1999:blog-8755629231838247325.post-26694726966119990232015-06-11T18:23:29.478-07:002015-06-11T18:23:29.478-07:00You are right mosra. The copy assignment operator ...You are right mosra. The copy assignment operator should call the destructor too.finalpatchhttps://www.blogger.com/profile/00977023159563294844noreply@blogger.comtag:blogger.com,1999:blog-8755629231838247325.post-78579243194996259842015-06-11T08:17:07.927-07:002015-06-11T08:17:07.927-07:00Great post, I was searching for something like thi...Great post, I was searching for something like this for some time...<br /><br />One note, though -- shouldn't the following line be also in the copy assignment operator to avoid leaks?<br /><br />reinterpret_cast(buf)->~DeferredCallBase();mosrahttps://www.blogger.com/profile/16160151545204274673noreply@blogger.comtag:blogger.com,1999:blog-8755629231838247325.post-72531794640199173962015-06-11T08:09:25.121-07:002015-06-11T08:09:25.121-07:00This seems to have similar behavior to std::functi...This seems to have similar behavior to std::function when it comes to heap allocations, and for similar reasons... can you elaborate on the heap allocation advantages of your class?Jeff Trullhttps://www.blogger.com/profile/14552765271690918879noreply@blogger.com