.
D 2014-09-06T22:52:46.844
L Allocation
P 084aa234cfa594878d112829531177942ebaa263
U dgp
W 4578
<h1>Source Files</h1>
* [/finfo?name=generic/tclAlloc.c|tclAlloc.c]
* [/finfo?name=generic/tclCkalloc.c|tclCkalloc.c]
* [/finfo?name=generic/tclThreadAlloc.c|tclThreadAlloc.c]
<h1>Public Interface</h1>
* ckalloc
* attemptckalloc
* ckfree
* ckrealloc
* attemptckrealloc
* Tcl_Alloc
* Tcl_AttemptAlloc
* Tcl_Free
* Tcl_Realloc
* Tcl_AttemptRealloc
* Tcl_DbCkalloc
* Tcl_AttemptDbCkalloc
* Tcl_DbCkfree
* Tcl_DbCkrealloc
* Tcl_AttemptDbCkrealloc
* Tcl_GetMemoryInfo
* Tcl_ValidateAllMemory
* Tcl_DumpActiveMemory
* Tcl_InitMemory
<h1>Private Interface</h1>
* TclInitAlloc
* TclFinalizeAllocSubsystem
* TclFinalizeMemorySubsystem
* TclpAlloc
* TclpFree
* TclpRealloc
* TclFreeAllocCache
* TclThreadAllocObj
* TclThreadFreeObj
* TclFinalizeThreadAlloc
* TclFinalizeThreadAllocThread
* TclpSysAlloc
* TclpSysFree
* TclpSysRealloc
* TclInitDbCkalloc
* TclDumpMemoryInfo
<h1>Directly Depends On Public Interface Of</h1>
* [Threads]
* [Embedding Support]
* [Object System and Fundamental Object Types]
* [Parsing and Evaluation]
* [Pathname Management]
* [Conversions From String]
* [Filesystem Access]
* <i>stdio.h</i>
* <i>ctype.h</i>
* <i>string.h</i>
<h1>Directly Depends On Private Interface of</h1>
* [Threads]
<h1>Discussion</h1>
This module handles dynamic allocation and free of memory.
The largest defect is that <b>Tcl_Alloc</b> takes an <i>unsigned int</i>
argument for the number of bytes to allocate, limiting the allocation size to
4 Gib. An allocator without such a low limitation must be part of Tcl 9.
A surprising feature for many is that <b>Tcl_Alloc</b> panics on an
allocation failure. The alternative <b>Tcl_AttemptAlloc</b> exists for
those who wish to choose it, but much of Tcl rests on foundations that will
be ripped away in any out-of-memory situation.
Many coders behave as if the performance of these memory allocators is
a burden to be avoided. The pooling system for <b>Tcl_Obj</b>, and the whole
<b>TclStack*</b> scheme of stack-patterned allocation are indications that
significant lengths are gone to in order to avoid calls to <b>Tcl_Alloc</b>.
An allocation system that behaved acceptably well in the first place might lead
to a great deal of code simplification.
As it currently exists, this is not so much a module as it is a collection of
alternative modules. There are at least 3 allocation systems here, and each
one may be overlaid with memory debugging facilities. The combination you
get in <b>Tcl_Alloc</b> is controlled by a set of compiler directives
at the time the <b>Tcl_Alloc</b> is compiled. This leads to a significant
problem that not all configurations are mutually compatible. This means
it's not all that hard to get into a situation where extensions and applications
are functionally incompatible because they've been compiled with different
directives. This is often described as "memdebug extensions only work in
memdebug interps", but the problem may well be more far-reaching than that.
It's a bit of an inelegance that the forms of the routines that support
re-configuration into memory debugging forms are the <b>*ck*</b>
so that code using the Tcl library is encouraged to call <b>ckalloc</b>
rather than <b>Tcl_Alloc</b>.
At least some parts of Tcl's memory management exhibit a <i>high water mark</i>
behavior where freed memory is not actually released to the system, but retained
by libtcl for later re-allocation. This is a poor fit for those programs that have
very large, but very temporary memory demands. It's not clear to me whether
that (mis-)behavior originates in this module, but a later wiki editor can revise this
into a more definitive statement.
Some branches exploring reforms in this module include
* [/timeline?r=mig-alloc-reform|mig-alloc-reform]
* [/timeline?r=mig-strip-brutal|mig-strip-brutal]
* [/timeline?r=nonmonotonic-obj-alloc|nonmonotonic-obj-alloc]
* [/timeline?r=novem-more-memory-API|novem-more-memory-API]
* [/timeline?r=novem-64bit-sizes|novem-64bit-sizes]
The dependency data above indicates a dependency on many other modules,
but that is due to the debugging layer. Separating this module into two parts,
one for debugging, the other just for the fundamental operations, the latter
depends only on <b>Tcl_Panic</b> and [Threads] and the system routines
for memory management.
Z 795648143a690672b5c02570d20a3d86