Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!ut-emx!ccwf.cc.utexas.edu From: android@ccwf.cc.utexas.edu (Andy Wilks) Newsgroups: comp.lang.c++ Subject: Re: How are strings efficiently concatenated? Message-ID: <50727@ut-emx.uucp> Date: 18 Jun 91 06:05:04 GMT References: <2825@umriscc.isc.umr.edu> <1991Jun17.234430.8877@intellistor.com> Sender: news@ut-emx.uucp Reply-To: android@ccwf.cc.utexas.edu (Andy Wilks) Organization: The University of Texas at Austin Lines: 34 In article <1991Jun17.234430.8877@intellistor.com> wicklund@intellistor.com (Tom Wicklund) writes: )In <2825@umriscc.isc.umr.edu> jamesh@cs.umr.edu (James Hartley) writes: ) )>The expression s1 + s2 will allocate space for "onetwo", but s0 will create )>a new copy "onetwo". How is the intermediate string deallocated? What I )>would really like to do is write efficient code for the following -- ) )> s0 = s1 + s2 + s3; ) ) )Another way is to implement an append operation analagous to the "<<" )of stream output: ) ) s0 = ""; ) s0 << s1 << s2 << s3; ) )Ideally this should then be merged into streams so that a string can )act as an input or output stream. Why don't you overload the "+" and "=" operators, have it return a string&, write constructors and destructors and let the compiler take care of the rest? This is very similar to the stream operator but the "+" would be a more natural operator for concat. /*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/ * I don't express opinions, I just follow orders... (___) * / (o o) / * Andy Wilks One of the few .sig's-> /-------\ / * / andy@fiskville.mc.utexas.edu with ASCII livestock. / | ||O / * android@ccwf.cc.utexas.edu * ||,---|| * / University of Texas at Austin ^^ ^^ / * copyright (c) 1934,1942,1961,1990,1991 BEVO * /*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/