String Buffers

version 5 by Jesse McGrew

  • Home page
  • Beginning
  • Previous
  • Next



  • Section 2b - Buffered things (continued)

    To decide which number is the maximum message length of (x - a buffered thing):
        decide on the buffer allocation of x.

    Allocating string buffer space is an activity.

    When play begins: carry out the allocating string buffer space activity;

    Rule for allocating string buffer space (this is the standard string buffer space allocation rule):
        repeat with board running through buffered things begin;
            if the buffer allocation of board is not 0, change the buffer shares of board to 0;
        end repeat;
        let RS be the total buffer shares of all buffered things; [remaining shares]
        if RS is not 0 begin;
            let RB be the total string buffer space; [remaining bytes]
            let the next offset be 0;
            repeat with board running through buffered things begin;
                if the buffer allocation of board is 0 or the buffer allocation of board is greater than RB begin;
                    let CS be the buffer shares of board; [current shares]
                    let X be (RB * CS) / RS;
                    [say "*** allocating [X] bytes to [the board] ([CS] shares)[line break]";]
                    change the buffer allocation of board to X;
                otherwise;
                    let X be the buffer allocation of board;
                end if;
                change the buffer offset of board to the next offset;
                increase the next offset by X;
                decrease RS by CS;
                decrease RB by X;
            end repeat;
        end if.

    After allocating string buffer space (this is the standard initial message assignment rule):
        repeat with x running through buffered things begin;
            if the initial message of x is not "", change the message of x to the initial message of x;
        end repeat.

    Definition: a buffered thing is blank if the message length of it is 0.
    Definition: a buffered thing is nonblank if it is not blank.