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

Matthew Wilcox
2007-10-24T02:35:27Z

On Tue, Oct 23, 2007 at 10:19:06PM -0400, Eric St-Laurent wrote:
> I don't know if copy-on-write semantics are really useful for current
> in-kernel uses, but I've coded and used a C++ string class like this in
> the past:

CoW isn't in the slightest bit helpful. The point of these is to
provide an accumulator, therefore the majority of accesses to these
stringbufs are writes.

> Multiple string objects can share the same data, by increasing the nrefs
> count, a new data is allocated if the string is modified and nrefs > 1.

If we were trying to get rid of char * throughout the kernel, that might
make some sense; stringbufs have a more limited target though.

> Even without copy-on-write semantics and reference counting, I think
> this approach is better because it uses 1 less "object" and allocation:
>
> struct string - "handle" (pointer really) to string data
> struct string_data - string data
>
> versus:
>
> struct stringbuf *sb - pointer to string object
> struct stringbuf - string object
> char *s (member of stringbuf) - string data

I think you missed the part of the patch where I said that the stringbuf
is normally allocated on the stack or as part of some other structure.
The only thing that should be allocated is the string itself.

--
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours. We can't possibly take such
a retrograde step."