Re: [PATCH 1/4] stringbuf: A string buffer implementation

Joe Perches
2007-10-26T03:42:12Z

On Fri, 2007-10-26 at 12:11 +1000, Rusty Russell wrote:
> On Thursday 25 October 2007 05:59:49 Matthew Wilcox wrote:
> > Consecutive calls to printk are non-atomic, which leads to various
> > implementations for accumulating strings which can be printed in one call.
> > This is a generic string buffer which can also be used for non-printk
> > purposes.

> This just seems like more optimization and complexity that we need.
> Interfaces using vsnprintf don't seem like good candidates for
> optimization.

Perhaps just tie stringbuf to printk and make stringbuf->buf
the same 1K size as the printk buffer?

no reallocs, no in-place out-of-memory handling
normal kzalloc and kfree of stringbuf * or add sb_alloc & sb_free

struct stringbuf {
int len;
char buf[1024];
}

/**
* sb_printf_append - append to a stringbuf
* @sb: a pointer to the stringbuf
* @fmt: printf-style format
*/
void sb_printf_append(struct stringbuf *sb, const char *fmt, ...)
{
va_list args;

va_start(args, fmt);
sb->len += vscnprintf(&sb->buf[len], sizeof(sb->buf) - sb->len, fmt, args);
va_end(args);
}
EXPORT_SYMBOL(sb_printf_append);