Re: How expensive are exceptions?
Mathias Gaunard wrote:
On Jun 16, 3:55 pm, Walter Bright <wal...@digitalmars-nospamm.com>
wrote:
For a generational GC, you can avoid scanning sections of memory that
you know haven't changed since the last time it was scanned. This is
done by implementing a "write barrier", which marks the section as
"changed and needs rescanning" when it is written to. One way to do this
is to instrument every write instruction. Another way is to mark those
sections' pages as "read only". Then, the hardware throws a "write
fault" exception when an instruction tries to write to it. You set up a
handler that intercepts the write fault, logs the faulting page as
"changed and need rescanning", then turns on the write enable bit for
the page, and restarts the instruction.
This is not practical if the exception unwinding is slow.
That's not a correct use of exceptions.
That's a hack.
Exceptions are meant for exceptions, nothing more, nothing less.
Using hardware write barriers in this manner is a well-known and
well-traveled path in implementing garbage collectors.
See "Garbage Collection" by Richard Jones and Rafael Lins
Hardware exceptions are also used for all kinds of other things, like
demand paged virtual memory, for example, and other forms of
virtualization. These form the basis of modern operating system design,
and are not a hack. The hardware is specifically designed to support
this, and SEH was specifically designed to make this stuff available to
user programs.
-------------
Walter Bright
http://www.digitalmars.com C, C++, D programming language compilers
http://www.astoriaseminar.com Extraordinary C++
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]