Path: utzoo!mnetor!uunet!husc6!mit-eddie!uw-beaver!cornell!rochester!PT.CS.CMU.EDU!K.GP.CS.CMU.EDU!lindsay From: lindsay@K.GP.CS.CMU.EDU (Donald Lindsay) Newsgroups: comp.arch Subject: Re: C machine Message-ID: <554@PT.CS.CMU.EDU> Date: 20 Dec 87 21:48:52 GMT References: <261@ivory.SanDiego.NCR.COM> <164@sdeggo.UUCP> <3078@phri.UUCP> Sender: netnews@PT.CS.CMU.EDU Organization: Carnegie-Mellon University, CS/RI Lines: 23 Keywords: nul terminated strings There isn't any "right" string representation. But, there are things worth saying. Nul terminated strings: useful, simple. Length count at front: overhead, but some operations (like concatenation or block transfer) become easier. Dope vector: (i.e. a pointer to the string, with length count attached to the pointer, not to the string): more overhead, but some more operations are eased. (Substring can be done in-place, with no moved characters.) For example, suppose you want to read an entire text file to memory, and then treat it as strings. It makes no sense to copy it piecemeal. So, build dope vectors that point into the text region. Since you haven't written into the stuff, you can easily put big chunks out to another file. "All problems in computer science can be solved by adding layers of indirection" - old joke. We knew all this stuff years ago, so please, no rebuttals. -- Don lindsay@k.gp.cs.cmu.edu CMU Computer Science