[gclist] Re: "Ad hoc" storage management

Mark Hamburg mhamburg@Adobe.COM
Wed, 6 Sep 2000 11:00:39 -0700


>If we're counting ad hoc resource management techniques that aren't
>built into language runtimes, reference counting is clearly ahead of
>mark & sweep, but probably isn't in the lead.
>
>I'd suspect that the most common techniques are:
>
>  - Static deallocation:  Allocate without freeing and reclaim when the
>    program exits.  Applies to both statically and dynamically allocated
>    resources.
>
>  - Stack allocation:  Allocate on function entry, deallocate on exit.
>    Applies to both implicit allocation of local variables and explicit
>    allocation and deallocation.
>
>  - Exclusive ownership:  Ensure that each entity is owned by exactly
>    one entity and deallocate when the the owner disappears.  This is,
>    of course, an implicit reference count of 0 or 1.
>
>I've definitely seen memory, files, and windows dealt with using all
>three approaches more frequently than reference counting.  With good
>reason:  all three have much better performance than reference counting
>and are usually easier to implement correctly, even if they don't apply
>to all circumstances.
>
>Region analysis and linear logic are linguistic models that remove the
>ad hockery from stack allocation and exclusive ownership.

While static deallocation is a hack in my book, I would hardly call stack
allocation or exclusive ownership ad hoc. What they sometimes lack is good
linguistic support for making them safe. Oberon does quite well using stack
allocation safely. C++ auto_ptr's on the other hand, work well but are far
from safe.

It is interesting to look at how one can generalize these mechanisms while
preserving safety. Assuming you don't want to just defer everything to the
compiler, it becomes a tricky balancing act in language design to allow
programmers to convey their intent safely without using excessive verbiage.

Mark