Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'programmer': 0.03; 'from:addr:yahoo.co.uk': 0.04; 'string.': 0.05; 'amounts': 0.07; 'string': 0.09; 'bytes,': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'language.': 0.14; '3.3,': 0.16; 'cares': 0.16; 'make,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'utterly': 0.16; 'language': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'thu,': 0.19; 'feb': 0.22; 'memory': 0.22; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'integer': 0.24; 'sorry,': 0.24; 'string,': 0.24; 'looks': 0.24; '---': 0.24; 'sort': 0.25; 'developers': 0.25; 'least': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'character': 0.29; 'compared': 0.30; "i'm": 0.30; 'easier': 0.31; 'convenience': 0.31; "d'aprano": 0.31; 'purely': 0.31; 'really,': 0.31; 'reduced': 0.31; 'steven': 0.31; 'subject:size': 0.31; 'trivial': 0.31; 'yes.': 0.31; 'core': 0.34; 'could': 0.34; 'agree': 0.35; 'except': 0.35; 'but': 0.35; 'in:': 0.36; 'programming,': 0.36; 'needed': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'short': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'free': 0.61; 'viruses': 0.61; 'you.': 0.62; 'save': 0.62; 'times': 0.62; 'protection': 0.63; 'our': 0.64; 'more': 0.64; 'antivirus': 0.68; 'lose': 0.68; 'nobody': 0.68; 'million': 0.74; 'savings': 0.81; 'complexity': 0.84; 'fifty': 0.84; 'safety.': 0.84; 'horror': 0.91; 'reducing': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Finding size of Variable Date: Sat, 08 Feb 2014 13:17:08 +0000 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> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-146-6-70.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 In-Reply-To: <52f59aeb$0$29972$c3e8da3$5496439d@news.astraweb.com> X-Antivirus: avast! (VPS 140208-0, 08/02/2014), Outbound message X-Antivirus-Status: Clean 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: 60 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391865456 news.xs4all.nl 2870 [2001:888:2000:d::a6]:52013 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65676 On 08/02/2014 02:48, Steven D'Aprano wrote: > On Thu, 06 Feb 2014 05:51:54 -0800, wxjmfauth wrote: > >> Sorry, I'm only pointing you may lose memory when working with short >> strings as it was explained. I really, very really, do not see what is >> absurd or obsure in: >> >>>>> sys.getsizeof('abc' + 'EURO') >> 46 >>>>> sys.getsizeof(('abc' + 'EURO').encode('utf-32')) >> 37 > > > Why do you care about NINE bytes? The least amount of memory in any PC > that I know about is 500000000 bytes, more than fifty million times more. > And you are whinging about wasting nine bytes? > > If you care about that lousy nine bytes, Python is not the language for > you. Go and program in C, where you can spent ten or twenty times longer > programming, but save nine bytes in every string. > > Nobody cares about your memory "benchmark" except you. Python is not > designed to save memory, Python is designed to use as much memory as > needed to give the programmer an easier job. In C, I can store a single > integer in a single byte. In Python, horror upon horrors, it takes 14 > bytes!!! > > py> sys.getsizeof(1) > 14 > > We consider it A GOOD THING that Python spends memory for programmer > convenience and safety. Python looks for memory optimizations when it can > save large amounts of memory, not utterly trivial amounts. So in a Python > wide build, a ten-thousand block character string requires a little bit > more than 40KB. In Python 3.3, that can be reduced to only 10KB for a > purely Latin-1 string, or 20K for a string without any astral characters. > That's the sort of memory savings that are worthwhile, reducing memory > usage by 75%. > > Could Python save memory by using UTF-8? Yes. But it would cost > complexity and time, strings would be even slower than they are now. That > is not a trade-off that the core developers have chosen to make, and I > agree with them. > > > This is a C +1 to save memory when compared against this Python +1 :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com