Open marcelnabeck opened 2 years ago
Hi, currently, the listener function is still a "global function", for example, see the below code:
So, in this issue, you mentioned that "an object" could be used. Do you mean the listener could be a std::function
?
Hi,
yes, std::function
would be an option to implement this.
Unfortunately std::function
is very expensive in terms of memory consumption and execution time, and also potentially allocates memory in the heap. This makes it unsuitable for most embedded applications...
As alternative I was thinking about using etl::delegate
from the Embedded Template Library, which is much more lightweight. This would add a dependency to a big external library which I also didn't want.
Probably the best option is the creation of an interface class which the user has to implement. Then an object of this class could be used to replace current function pointers and it's object oriented.
Hi, thanks for the quick response and explanation.
I'm using this tinyframe library in either a embedded application running in a MCU, also I use this library in a PC C++ program.
I'm OK about the direction.
BTW: you solved the problem I encountered several years ago, see here: multiple instances with different frame structure?.
Thanks.
Include an object on which the Listener callbacks are called: