From ruby-talk-admin@ruby-lang.org Fri Dec 16 01:17:44 2005 Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (8.12.3/8.12.3/Debian-6.6) with ESMTP id jBFGHiZk027387; Fri, 16 Dec 2005 01:17:44 +0900 Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 96B2E5CAF; Fri, 16 Dec 2005 01:17:45 +0900 (JST) Received: from localhost (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 84222F0489B; Fri, 16 Dec 2005 01:17:49 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 49FD4F04850; Fri, 16 Dec 2005 01:17:48 +0900 (JST) Received: from beryllium.ruby-lang.org (beryllium.ruby-lang.org [210.163.138.100]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 1795D63002C; Fri, 16 Dec 2005 01:17:51 +0900 (JST) Received: from beryllium.ruby-lang.org (beryllium.ruby-lang.org [127.0.0.1]) by beryllium.ruby-lang.org (Postfix) with ESMTP id 0B2AE33F21; Fri, 16 Dec 2005 01:17:47 +0900 (JST) Received: from localhost (beryllium.ruby-lang.org [127.0.0.1]) by beryllium.ruby-lang.org (Postfix) with ESMTP id D107033F32 for ; Fri, 16 Dec 2005 01:17:39 +0900 (JST) Received: from beryllium.ruby-lang.org ([127.0.0.1]) by localhost (beryllium.ruby-lang.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 31266-09 for ; Fri, 16 Dec 2005 01:17:39 +0900 (JST) Received: from sinus.lauschmusik.de (sinus.lauschmusik.de [213.95.32.201]) by beryllium.ruby-lang.org (Postfix) with ESMTP id 6485033F21 for ; Fri, 16 Dec 2005 01:17:39 +0900 (JST) Received: from localhost ([127.0.0.1] helo=localhost.localdomain) by sinus.lauschmusik.de with esmtp (Exim 4.50) id 1Emvkz-0004he-AZ for ruby-talk@ruby-lang.org; Thu, 15 Dec 2005 17:15:01 +0100 Received: from individual.net (individual.net) by sinus.lauschmusik.de with NTTP id 166223 for ; Thu Dec 15 17:15:01 CET 2005 Received: from [unknown] by individual.net (unknown) with NNTP id 166223 for ; Thu Dec 15 17:15:01 CET 2005 Received: from Usenet via a Usenet to mail gateway located at lauschmusik.de. This service provided as a courtesy to the ruby-talk mailing list. If this message is SPAM, its ultimate origin is Usenet, not this gateway program. All subscribers to the ruby-talk mailing list agree to receive the Usenet postings made to comp.lang.ruby via this gateway. Please see http://www.ruby-lang.org/ruby-talk-usenet-policy.html. Delivered-To: ruby-talk@ruby-lang.org Date: Fri, 16 Dec 2005 01:17:40 +0900 Posted: Thu, 15 Dec 2005 17:09:02 +0100 From: "Robert Klemme" Reply-To: ruby-talk@ruby-lang.org Subject: Re: Question of reference and (sub)strings. To: ruby-talk@ruby-lang.org (ruby-talk ML) Message-Id: <40dj3kF190h7dU1@individual.net> References: <40cuekF19kr0tU1@individual.net> <43A18FB9.3050208@shic.co.uk> X-ML-Name: ruby-talk X-Mail-Count: 57 X-MLServer: fml [fml 4.0.3 release (20011202/4.0.3)]; post only (only members can post) X-ML-Info: If you have a question, send e-mail with the body "help" (without quotes) to the address ruby-talk-ctl@ruby-lang.org; help= X-Newsreader: Microsoft Outlook Express 6.00.2800.1506 X-Original-To: ruby-talk@ruby-lang.org Path: noris.net!news.osn.de!diablo1-ffm.news.osn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Newsgroups: comp.lang.ruby X-Trace: individual.net GADz18nnSaisz1QcfLX7RwmizdDQAm6U/UN+Fpdzn+BWHPbls= X-Priority: 3 X-MSMail-Priority: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 X-From-Usenet: see Received: header above. X-rubymirror: yes X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ruby-lang.org X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on beryllium.ruby-lang.org X-Spam-Level: X-Spam-Status: No, score=-4.4 required=7.0 tests=AWL,BAYES_00, CONTENT_TYPE_PRESENT,FAKEDWORD_ATMARK,MSGID_FROM_MTA_HEADER, PRIORITY_NO_NAME,QENCPTR2,RCVDFRMLOCALIP autolearn=no version=3.0.3 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Precedence: bulk Lines: 53 List-Id: ruby-talk.ruby-lang.org List-Software: fml [fml 4.0.3 release (20011202/4.0.3)] List-Post: List-Owner: List-Help: List-Unsubscribe: X-Virus-Scanned: by AMaViS snapshot-20020531 Steve [RubyTalk] wrote: > Robert Klemme wrote: >>> I might be wrong >>> >> You're not. >> >>> - but I'm pretty sure that substrings in ruby are >>> created with copy-on-write. That is, when you take a substring, a >>> new block of memory isn't allocated to the new String, it >>> references the same block of memory as the original string - the >>> allocation of a new block of memory only occurs when one of the >>> strings is modified. >>> >> Exactly. It seems this would be the simplest solution. >> >> > That sounds like absolutely great news - a _very_ pleasant surprise. I > couldn't have hoped for anything better. (Thanks!) > > I assume that if I do something like: > > # Assume offsets is a pre-computed array of positive integer > positions into the String originalstr. Care to unveil a bit of the nature of the computation that yields those indexes? > # with offsets[0]==0 and offsets[-1]==@originalstr.size > @fields=Array.new (offsets.size-1) > for i in 1..(offsets.size) do > # I assume this next line is what is meant by a Ruby sub-string? > @fields[i-1]=@originalstr[offsets[i-1]..offsets[i]] > end > > .. and, assuming that @fields is exposed only as a read-only > attribute, that I can assume the memory it consumes to be independent > of the length of originalstr and dependent only upon numfields? You can help keeping this read only be freezing all strings involved. > While I've no reason to doubt this confirmed answer, by any chance can > someone suggest a good way to demonstrate that this is the case > without resorting to either using very large strings and looking at > VM usage of the interpreter process... or resorting to reviewing the > source to Ruby's implementation? The only additional method of verification that comes to mind is to ask Matz. :-) Kind regards robert