Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!decwrl!Angelo!lindy!news From: GQ.RLG@forsythe.stanford.edu (Dick Guertin) Newsgroups: comp.arch Subject: Re: String length Message-ID: <1944@lindy.Stanford.EDU> Date: 6 Feb 89 21:15:35 GMT Sender: news@lindy.Stanford.EDU Lines: 27 In article <28200268@mcdurb>, aglew@mcdurb.Urbana.Gould.COM writes: -> ->Abstract from: comp.arch 8281, 6 Feb 89, 56 lines. -> ->May I encourage people implementing string libraries to use an extra ->level of indirection? Instead of length immediately preceding the string, ->let length be associated with a pointer to the string. Makes ->substringing operations much easier, and has the ability to reduce ->unnecessary copies (at the risk of increased aliasing). -> -> +------+---+ -> |length|ptr| -> +------+---+ -> | -> +------+ -> | -> V -> +---+---+---+---+---+---+---+---+---+---+---+---+---+ -> | H | E | L | L | O | , | | W | O | R | L | D | \n| -> +---+---+---+---+---+---+---+---+---+---+---+---+---+ Such an implementation has adverse effects when the string is sent to/from an external device, such as a file. The 'length' must be with the string, or the string needs a terminator character. Furthermore, when a 'ptr' is changed to point to a new string, what happens to the 'length' information for the old string?