Re: Larry Wall, on Tcl
- From: "tom.rmadilo" <tom.rmadilo@xxxxxxxxx>
- Date: Wed, 12 Dec 2007 08:04:02 -0800 (PST)
On Dec 11, 3:32 pm, "Donal K. Fellows" <donal.k.fell...@xxxxxxxxx>
wrote:
tom.rmadilo wrote:
Donal's example below is a good example of how easy it is to write an
intelligent garbage collection routine.
No, it's Resource Allocation Is Initialization, a resource management
strategy developed originally in C++ that's trivial to adapt.
Good to know the technical term. Resource management gets right at the
heart
of the matter with Tcl. Maybe I have a simple view, but if you manage
your
resources (chans, memory, handles) correctly, you might not have too
much
garbage to collect. In most of my code, each namespace deals with a
particular set of data and the namespace has an [init] command.
Correct
operation would call this at the beginning of a particular chunk of
work and
potentially register cleanup:
namespace eval ::twt::db::handle {
variable initialized 0
variable ids
}
# First time a db handle is needed for a conn:
proc ::twt::db::handle::init { } {
ns_atclose ::twt::db::handle::reset
variable initialized 1
variable ids
array unset ids
}
proc ::twt::db::handle::reset { } {
variable initialized
variable ids
foreach id [array names ids] {
set pool [lindex $ids($id) 3]
set dataSource [lindex $ids($id) 1]
::twt::db::datasource::addPool $dataSource $pool
}
array unset ids
set initialized 0
}
So this namespace manages an array 'ids'. Now the user can use the
commands in
this namespace and not worry about initialization and resource
management.
Of course there are several other layers below this where the actual
resources are managed. This code just gets an exclusive reference to a
resource and makes sure it gets returned at the end of the work cycle.
This is kind of like how a public library works. You check out a book,
the library records the fact and relies on you to return it on time.
But in case that doesn't work out, they have ways of dealing with the
situation because they have a record of what was supposed to happen.
.
- References:
- Larry Wall, on Tcl
- From: Bryan Oakley
- Re: Larry Wall, on Tcl
- From: tom.rmadilo
- Re: Larry Wall, on Tcl
- From: Bryan Oakley
- Re: Larry Wall, on Tcl
- From: tom.rmadilo
- Re: Larry Wall, on Tcl
- From: Cameron Laird
- Re: Larry Wall, on Tcl
- From: Darren New
- Re: Larry Wall, on Tcl
- From: Alan Anderson
- Re: Larry Wall, on Tcl
- From: Darren New
- Re: Larry Wall, on Tcl
- From: tom.rmadilo
- Re: Larry Wall, on Tcl
- From: Darren New
- Re: Larry Wall, on Tcl
- From: tom.rmadilo
- Re: Larry Wall, on Tcl
- From: Donal K. Fellows
- Larry Wall, on Tcl
- Prev by Date: Re: Tcl, pipes and DJGPP
- Next by Date: Re: A gridplus question
- Previous by thread: Re: Larry Wall, on Tcl
- Next by thread: Re: Larry Wall, on Tcl
- Index(es):
Relevant Pages
|