4 ms·
Exceptions are not about going from one place to another. It's about unwinding the stack properly and calling the destructors of variables on the stack. This is
by halayli 11y ago
Exceptions are not about going from one place to another. It's about unwinding the stack properly and calling the destructors of variables on the stack. This is not a close emulation at all.
- rwmj 11y agoWhile I'm not saying this is a good idea, you can combine a pool allocator with longjmp exceptions to get an approximation of unwinding. It requires that you are very careful about structuring your code, but I once wrote a whole web server this way: http://git.annexia.org/?p=rws.git;a=tree http://git.annexia.org/?p=rws.git;a=tree (using: http://git.annexia.org/?p=c2lib.git;a=tree http://git.annexia.org/?p=c2lib.git;a=tree ).
- halayli 11y agoBut sometimes it's not just memory. It can be files you need to close, or any other resource held.
- chaz72 11y agoThat too can be queued up, with a list of functions to call to free those resources.
- halayli 11y agoHe was referring to a memory pool allocator. But regardless, good luck with the approach.
- rwmj 11y agoPool allocators can easily deal with non-memory resources. The one I wrote in c2lib could.