Skip to content

RFC bipbup_offer() : try to fit after A before activating B #6

@fenugrec

Description

@fenugrec

Here's a different implementation of bipbup_offer() :

  • if B is in use, append data there (no change)
  • if B is unused, and there is enough space after A, append data there
  • fallback : activate B area and write data there, if possible.

Advantage is slightly increased efficiency, at basically 0 cost.

Note : currently untested

*****
int bipbuf_offer(bipbuf_t* me, const unsigned char *data, const int size)
{
    if (1 == me->b_inuse)
    {
	/* check available space between region B and region A */
        if ((me->a_start - me->b_end) < size) return 0;

        memcpy(me->data + me->b_end, data, size);
        me->b_end += size;
	return size;
    }

    /* no B area (yet). Check if we can fit in the remaining space */
    if (size < (me->size - me->a_end))
    {
        memcpy(me->data + me->a_end, data, size);
        me->a_end += size;
	return size;
    }

    /* didn't fit, activate B if possible */
    if (size > (me->a_start))
    {
	/* won't fit */
	return 0;
    }

    me->b_inuse = 1;
    memcpy(me->data, data, size);
    me->b_end += size;
    return size;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions