On 3 Aug 2007, at 15:14, Peter da Silva wrote:
Ultimately, though, something like this structure tends to raise its head:

struct _buffer {
    int size;   // size of buffer
    int length; // size of data in buffer
#ifdef BUFFERGAP
    int gap;    // start of gap
#endif
#ifdef RESIZABLE
    char *data; // start address of buffer
#else
    char data[]; // buffer follows header
#endif
};

Oooh, gap-in-the-middle buffer - my favourite :) (anyone remember WordWise?)

If we're really bothered I *think* you tend to end up with slightly more compact code if you do

struct _buffer {
    int size;
    int gap_lo; // start of gap
    int gap_hi; // end of gap
}

If you want the ungapped variant you can just drop gap_hi and assume gap_hi == size. Then gap_lo == length.

--
Andy Armstrong, hexten.net

Reply via email to