Tcl Source Code

Preservation
Login

Source Files

Public Routines

Private Routines

Directly Depends On Public Routines From

Directly Depends On Private Routines From

Discussion

This module provides a solution to the important problem of managing shared interest in allocated memory.

Use of mutexes is needed to be safe for general use, but harms performance.

Implementation as a linear scan suggests the solution does not scale well at all. An effort to examine alternatives was made in novem-ak-preserve-experiments.

Wherever thread isolation and refcounting can be employed instead, they probably ought to be.

Completely different approaches such as some kind of garbage collection scheme might also avoid the drawbacks here.

The private export TclFinalizePreserve is needed so that finalization of these facilities can be delayed past all the users of them.

The TclHandle* set of routines seems to be an alternative set of tools for the same problem that has not caught on among the internals for unknown reasons and has never been exported either. These routines have no mutex protections and are built on a refcounting scheme, so they are only suitable for thread-isolated resources. The only existing use of these routines is for the Tcl_Interp struct which does have thread isolation as a known constraint.

The limitation of refcount values to the int range is probably not an important problem here.