On Oct 12, 3:29 pm, David Abrahams <d...@boostpro.com> wrote:
on Sat Oct 04 2008, JoshuaMaurice-AT-gmail.com wrote:
And I really, really like exceptions and RAII. Damn. Disclaimer: This
doesn't kill all of RAII, but it kills some of it. It effectively
forces two phase construction for most classes if you want efficient
code on all platforms, and that makes me very sad.
And how, exactly, is two-phase construction going to save you cycles?
To have single phase construction, constructors must acquires
resources. Acquiring resources can fail. User's must be able to know
if acquiring a resource fails. The only way I know of doing this is
with exceptions or 'zombie' objects. Exceptions carry significant
overhead on some implementations, so we're left with zombie objects,
and a function to query if it's a zombie.
Resource r;
if (r.isZombie())
return false;
Otherwise, we can do two phase construction, acquiring resources in
init(), and foregoing all exception use. It is very much like the
above approach; a zombie state is still required.
Resource r;
if (!r.init())
return false;
The bad compilers which handle exceptions poorly can be configured to
introduce no exception overhead in these two examples as nothing here
throws, avoiding the significant penalty of exception overhead.
Maybe I'm missing something. If the user needs the ultimate effect of
nonthrowing phases in the 2-phase case. If both phases could be
2-phase construction. Otherwise, phase 2 can throw, and the compiler is
[ comp.lang.c++.moderated. First time posters: Do this! ]