octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: unwind_protect improved


From: Jaroslav Hajek
Subject: FYI: unwind_protect improved
Date: Tue, 23 Jun 2009 08:48:31 +0200

hi all,

to solve certain problems, including
http://www.nabble.com/3.2.0-compile-error-on-FreeBSD-7.2-amd64-(sig_atomic_t-!%3D-int-on-amd64)-td24124769.html#a24124769
,
I have improved the design of the unwind_protect class somewhat.

Summary:

There's a generic unwind_protect::protect_var method able to handle a
variable of any assignable & copyable class.
unwind_protect::protect_mem is also provided though it will probably
be very seldom used (given that you can protect a NDArray or whatever
with protect_var).

using string tags for unwind_protect frames is now deprecated:

  unwind_protect::begin_frame ("tree_evaluator::visit_simple_for_command");
...
  unwind_protect::run_frame ("tree_evaluator::visit_simple_for_command");

In particular, if you misspelled the string in run_frame, it would
silently run all frames down the stack (!).
The proper usage is now:

  unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame ();
...
  unwind_protect::run_frame (uwp_frame);

which allocates the frame info as a local variable (in fact, it's
simply the stacksize at the moment of query). This is also somewhat
more efficient, as there's no string manipulation when processing the
stack, neither is there need to store them in the stack.

The old tags mechanism is still supported, but the methods are marked
as deprecated. They should be removed at some point.

It is also possible to protect a single variable locally, if
performance is of particular concern:

{
   unwind_protect::restore_var<bool> flag_protect (flag); // will
auto-restore flag at end of block
   flag = temporary value;
   ...
}

this is more efficient because the compiler can inline everything.

Comments?

-- 
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


reply via email to

[Prev in Thread] Current Thread [Next in Thread]