Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'explicitly': 0.05; 'indexing': 0.07; 'memory.': 0.07; 'string': 0.09; '(unicode': 0.09; '32-bit': 0.09; 'falls': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'worse': 0.09; 'python': 0.11; '"python': 0.16; '-tkc': 0.16; 'do!': 0.16; 'encodings': 0.16; 'opposite': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'string)': 0.16; 'width.': 0.16; 'zero,': 0.16; 'all.': 0.16; 'ignore': 0.16; 'wrote:': 0.18; 'pointed': 0.19; "skip:' 30": 0.19; 'memory': 0.22; 'header:User-Agent:1': 0.23; 'case.': 0.24; 'him.': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; 'tim': 0.29; "doesn't": 0.30; 'characters': 0.30; 'gives': 0.31; "skip:' 10": 0.31; 'chase': 0.31; 'subject:size': 0.31; '(e.g.': 0.33; 'cases': 0.33; 'to:addr :python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'space': 0.40; 'how': 0.40; 'up,': 0.60; 'full': 0.61; 'matter': 0.61; 'back': 0.62; 'save': 0.62; 'email addr:gmail.com': 0.63; 'debate': 0.68; 'saving': 0.69; 'engage': 0.74; 'gain': 0.79; 'everything,': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ned Batchelder Subject: Re: Finding size of Variable Date: Mon, 10 Feb 2014 10:02:50 -0500 References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <7e7d3200-a4ae-4842-ad8d-68b4435b9006@googlegroups.com> <52f219c5$0$29972$c3e8da3$5496439d@news.astraweb.com> <888bd2fc-54b0-4c46-9d7b-d81d01a78b52@googlegroups.com> <52f59aeb$0$29972$c3e8da3$5496439d@news.astraweb.com> <20140210084308.7727c0fd@bigbox.christie.dr> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 18.189.30.229 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 In-Reply-To: <20140210084308.7727c0fd@bigbox.christie.dr> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392044582 news.xs4all.nl 2898 [2001:888:2000:d::a6]:42694 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65821 On 2/10/14 9:43 AM, Tim Chase wrote: > On 2014-02-10 06:07, wxjmfauth@gmail.com wrote: >> Python does not save memory at all. A str (unicode string) >> uses less memory only - and only - because and when one uses >> explicitly characters which are consuming less memory. >> >> Not only the memory gain is zero, Python falls back to the >> worse case. >> >>>>> sys.getsizeof('a' * 1000000) >> 1000025 >>>>> sys.getsizeof('a' * 1000000 + 'oe') >> 2000040 >>>>> sys.getsizeof('a' * 1000000 + 'oe' + '\U00010000') >> 4000048 > > If Python used UTF-32 for EVERYTHING, then all three of those cases > would be 4000048, so it clearly disproves your claim that "python > does not save memory at all". > >> The opposite of what the utf8/utf16 do! >> >>>>> sys.getsizeof(('a' * 1000000 + 'oe' + >>>>> '\U00010000').encode('utf-8')) >> 1000023 >>>>> sys.getsizeof(('a' * 1000000 + 'oe' + >>>>> '\U00010000').encode('utf-16')) >> 2000025 > > However, as pointed out repeatedly, string-indexing in fixed-width > encodings are O(1) while indexing into variable-width encodings (e.g. > UTF8/UTF16) are O(N). The FSR gives the benefits of O(1) indexing > while saving space when a string doesn't need to use a full 32-bit > width. > > -tkc > > > Please don't engage in this debate with JMF. His mind is made up, and he will not be swayed, no matter how persuasive and reasonable your arguments. Just ignore him. -- Ned Batchelder, http://nedbatchelder.com