Comment by usefulcat

Comment by usefulcat 6 months ago

1 reply

> though that means you have to heap-allocate all your lambdas

I think whether or not you have to allocate from the heap depends on the lifetime of the lambda. Virtual methods also work just fine on stack-allocated objects.

OskarS 6 months ago

Fair point, but generally speaking, callbacks tend to escape the scopes they are in (if you have a callback for ”user clicked mouse”, it’s likely not going to be triggered in your current scope), so stack-allocation isn’t really an option.

But yes, fair point: they can be stack or statically allocated as well.