3 ms·
But the compiler doesn't optimize out the constructor, right? It can't. In an RTOS of all places, that seems awfully expensive. One generally avoids wasted res
by xyzzy_plugh 9y ago
But the compiler doesn't optimize out the constructor, right? It can't.
In an RTOS of all places, that seems awfully expensive. One generally avoids wasted resources in embedded -- the trade-off is it requires more care during development.
I've never seen RAII work well in an embedded system. Not being able to handle exceptions or errors during destruction ruins everything.
- monocasa 9y ago> But the compiler doesn't optimize out the constructor, right? It can't. > In an RTOS of all places, that seems awfully expensive. One generally avoids wasted resources in embedded -- the trade-off is it requires more care during development. The compiler has no issues "optimizing out" the constructor in my experience. The asm looks just like the equivalent C in all of the cases I've seen. > I've never seen RAII work well in an embedded system. Not being able to handle exceptions or errors during destruction ruins everything. I mean, we disallow exceptions anyway. And we use RAII for objects where there isn't a weird failure case to be handled like my example of thread priority guards.
- fdsfsafasfdas 9y agoDisabling exceptions has solved this. There are no need for exceptions in the kernel, and the cost is high.
- concede_pluto 9y agoIsn't table-driven stack unwinding cheaper than having a bunch of functions each check an error code and return to their caller?
- monocasa 9y agoThe practicalities of bare metal programming means that a lot of the time an individual work item has to jump contexts (ie. stacks and register sets) in a way that doesn't map cleanly to C++ style exceptions.