-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Description
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
Labels
No labels