Re: pseudo-specs for a String class

From: Adrian Chadd <adrian_at_squid-cache.org>
Date: Wed, 27 Aug 2008 17:27:45 +0800

2008/8/27 Kinkie <gkinkie_at_gmail.com>:

>> * Memory: some chunk of contiguous memory somewhere;
>> * MemoryRegion: some reference to { Memory, offset, length }
>> * String: a MemoryRegion and some routines to manipulate it
>
> I'm unconvinced. What's the purpose of a MemoryRegion if you can't
> manipulate it?
> In C, it makes sense to provide different API: strings provide
> different semantics than char* (they're null-terminated).
>
> But here?
> Everything is bounds-safe or it's not worth the effort.
> NULL-termination is optional and only used when exporting the
> underlying data..
>
> I'm being very pragmatic here: if it behaves like a string, it is a
> string, despite the fact that it might actually be a buffer, or a
> blob.

I had a long ranty email with lots of points, but I'll summarise and
save y'all the trouble.

A memory region can be manipulated (passed into vector IO, modified
with COW or not semantics, etc). Its just an array of bytes.

A string includes things like potentially caring about character
encoding in things like length calculations, comparisons, etc. A
memory region doesn't. A string is generally a representation of
printable data; a memory region isn't.

A string gets the benefits of a memory region (reference counting,
vectorised IO, etc) and just adds functionality on top of it.

Would you use a "String" as the reference counted type for say, the
memory store?

Adrian
Received on Wed Aug 27 2008 - 09:27:50 MDT

This archive was generated by hypermail 2.2.0 : Wed Aug 27 2008 - 12:00:06 MDT