"Karl E. Peterson" <karl@mvps.org> wrote in message <news:3c191652$1@147.208.176.211>...

> Well, I'm back late to the party, I see. <g> Sure sounds like a fun exercise,
> regardless. No better way to learn than to defy stupidity and pay attention to what
> happens, eh!? <vbg>


It's also fun to ask *** was Microsoft thinking? Why didn't they combine
reference counting with something like the old HLSTR? The string buffer
could have a reference count in front of the characters, while the string
descriptor would have a pointer to the reference count in addition to the
length and the first character. This would make string copying and even
the Left, Mid, and Right functions extremely fast on long strings, since
there would be absolutely no actual string copying whatsoever! There may
also be less heap thrash, since a string descriptor consisting of two
pointers and a length is hardly too large to live on the stack. However,
this raises the spectre of the last reference to a very long string being
the result of, say, Right$(vls, 1), tying up memory unnecessarily for who
knows how long. Modifying in place could also become a little slower,
since the reference count needs to be checked first -- if it isn't 1, a
new buffer must be built for the result. However, if we also track the
buffer's "real" length next to the reference count, the door is open to
taking the sting out of repeated concatenations without having to resort
to a separate StringBuffer class or the like.

Everything you never wanted to know about BSTR and HLSTR but were afraid
to ask: http://oreilly.com/catalog/win32api/chapter/ch06.html

--
Joe Foster <mailto:jlfoster%40znet.com> Got Thetans? <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above They're coming to
because my cats have apparently learned to type. take me away, ha ha!