[TUHS] Memory management in Dennis Ritchie's C Compiler

Steffen Nurpmeso steffen at sdaoden.eu
Tue Aug 18 09:40:13 AEST 2020

Richard Salz wrote in
 <CAFH29tpbNrUKVP2hp25wdu9BYCxQr+RrmcWJ8F+SbtwsGE4VKw at mail.gmail.com>:
 |Apache has the "pool" concept, per-request storage; there are a few

And BSD Mail had the "stringdope" of Kurt Shoens from the very
start in 1978.  It serves allocations of various size until reset
time.  (Different to the Apache thing it does not support
destructor calls -- if i recall the Apache stuff, i have looked
into that two decades ago.)

I personally had objects caches and fluctuating object caches
backed by generic C types

        pub GOCache(uir _objsz, uir _growby=8-1);
        pub uir count(void) const { return(m_count); }
        pub void *alloc(void);
        pub GOCache &free(void *_ptr);
        pub GOCache &clear(void);
        pub GOCache &swap(GOCache &_t);

and used via all-inline template wrappers

  template<class T> class OCache : private GOCache{
    OCache(uir _growby=8-1) : Super(szof(T), _growby) {}
    pub T *newObject(void) { return(SF_newHeap(T, Super::alloc())); }
    pub OCache &delObject(T *_tptr){
      _AssertRetThis(_tptr != NIL);

The difference was that the normal could not free individual
chunks, the other could

      pri union Atom{
        Chunk   *owner; // used
        Atom    *next;  // free

      pri struct Chunk{
        Chunk   *right;
        Atom    *free;  // freelist
        ui1     *top;   // cast point or NIL if full
        uir     count;  // user pointers this Chunk


      pri struct Atom{
        Atom    *next;

      pri struct Chunk{
        Chunk   *right;
        ui1     *top;   // cast point or NIL if full

(here the free Atom free list was part of the cache object).
That even worked out fine to serve nodes on hashmap and list
objects, in practice.

 |   https://commons.apache.org/proper/commons-pool/ (java)
 |   http://www.apachetutor.org/dev/pools (C server)

|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)

More information about the TUHS mailing list