Skip to content
Tcl Source Code Artifact [083b5b9702]
Login

Artifact [083b5b9702]

Artifact 083b5b970298d28c54c64099c68ab7aeacc1fbc5:

Wiki page [Preservation] by dgp on 2014-08-29 11:31:15.
D 2014-08-29T11:31:15.072
L Preservation
P 19178cc41cb950d7c74ebe8d94a1a7bd56602c16
U dgp
W 1860
<h1>Source Files</h1>
  *  [/finfo?name=generic/tclPreserve.c|tclPreserve.c]

<h1>Public Routines</h1>
  *  Tcl_Preserve
  *  Tcl_Release
  *  Tcl_EventuallyFree

<h1>Private Routines</h1>
  *  TclFinalizePreserve
  *  TclHandleCreate
  *  TclHandleFree
  *  TclHandlePreserve
  *  TclHandleRelease

<h1>Directly Depends On Public Routines From</h1>
  *  [Threads]
  *  [Embedding Support]
  *  [Allocation]

<h1>Directly Depends On Private Routines From</h1>
  *  <i>None</i>

<h1>Discussion</h1>

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 [/timeline?r=novem-ak-preserve-experiments|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 <b>TclFinalizePreserve</b> is needed so that
finalization of these facilities can be delayed past all the users
of them.

The <b>TclHandle*</b> 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 <b>Tcl_Interp</b> 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.

Z 574e3eedea0bee3e1f89d515cf0ca1ac