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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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);


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux