template<unsigned N>
class miosix::Callback< N >
A Callback works just like an std::tr1::function, but has some additional limitations. First, it can only accept function objects that take void as a parameter and return void, and second if the size of the implementation-defined type returned by bind is larger than N a compile-time error is generated. Also, calling an empty Callback does nothing, while doing the same on a tr1::function results in an exception being thrown.
The reason why one would want to use this class is because, other than the limitations, this class also offers a guarantee: it will never allocate data on the heap. It is not just a matter of code speed: in Miosix calling new/delete/malloc/free from an interrupt routine produces undefined behaviour, so this class enables binding function calls form an interrupt safely.
- Parameters
-
N | the size in bytes that an instance of this class reserves to store the function objects. If the line starting with 'typedef char check1' starts failing it means it is time to increase this number. The size of an instance of this object is N+sizeof(void (*)()), but with N rounded by excess to four byte boundaries. |