Re-cap prior buffer management schemes.

0 views
Skip to first unread message

Stephen Dennis

unread,
Jan 22, 2007, 1:54:29 PM1/22/07
to tinym...@googlegroups.com

Scheme for TinyMUX 2.4 and prior as well as other related codebases:

             A B C D E ...
             ^         ^
             |         |
char *buff---/         |
char **bufc------------/


To null-terminate: *(*bufc) = '\0';
To determine length: size_t n = *bufc - buff

Since append is a common operation, bufc is useful. Only a single allocation
pool of lbufs is necessary to support this.


Scheme for TinyMUX 2.6 reference counting of global registers:

Global registers are never appended or modified.  They are only set and used.
At the end of each queue cycle, all registers are cleared which has the effect
of releasing all the references.  In the example below, the lbuf remains
allocated until both reg_ref1 and reg_ref2 are released.  This scheme requires
three pools: reg_refs, lbuf_refs, and lbufs.

struct reg_ref
{
    int      refcount; // How many references exist for this value?
    lbuf_ref *lbuf;    // Which lbuf is holding the value?

    // Length and null-terminated string stored in the above lbuf.
    //
    size_t   reg_len;
    char    *reg_ptr;
};

struct lbuf_ref
{
    int      refcount;  // How many references are using this lbuf?
    char    *lbuf_ptr;  // LBUF_SIZE-ed buffer allocated with alloc_lbuf().
};

 

                      A B C D E '\0' ... 0 1 2 '\0' ...
                      ^                  ^
lbuf_ref1:            |                  |
 ^  lbuf_ptr----------/                  |
 |  refcount = 2      |                  |
 |                    |                  |
 |                    |                  |
 |                    |                  |
 |    reg_ref1:       |                  |
 \------lbuf          |                  |
 |      reg_ptr-------/                  |
 |      reg_len = 5                      |
 |      refcount = 1                     |
 |                                       |
 |  reg_ref2:                            |
 \------lbuf                             |
        reg_ptr--------------------------/
        reg_len = 3
        refcount = 1
 
Reply all
Reply to author
Forward
0 new messages