RE: resource construction WAS: [GD-General] longjmp for C++
Brought to you by:
vexxed72
From: Matt D. <ma...@co...> - 2002-01-14 09:51:24
|
-- Let me know when this winds back to longjmp. :) Really the only way to do it class-safe is with C++ exceptions. But this has two major drawbacks. Firstly, your classes need to be stack instantiations rather than have them created on the heap. Your classes should destruct properly then. Secondly, having an exception handler at such a high-level (i.e. somewhere around the main loop) adds overhead that filters into the lower-level functions. If you can live with that, thats fine. The only alternative is to have code that tracks what resources you have so you can 'delete' them in one foul swoop (direct X resources, memory heaps etc) then resort to your C-style longjmp. There's nothing wrong in using HeapCreate, HeapDestroy etc. in your own memory allocation routines. Just use the HeapAlloc function inplace of the alloc or new call (whatever creates your user-defined 'heap') so that HeapDestroy can still be useful. Cheers, Matt Davies Programmer, Confounding Factor ma...@co... www.confounding-factor.com |