Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4a.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; 'pypy': 0.07; 'assuming': 0.09; 'integers': 0.09; 'mess': 0.09; 'objects,': 0.09; 'operator,': 0.09; 'pretend': 0.09; 'subject:into': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '"object': 0.16; '"small"': 0.16; '24,': 0.16; 'block:': 0.16; 'broken.': 0.16; 'elsewhere.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'identities': 0.16; 'integers;': 0.16; 'objects.': 0.16; 'range.': 0.16; 'set,': 0.16; 'subject:variable': 0.16; 'wrote:': 0.18; 'bit': 0.19; '(where': 0.19; 'unlike': 0.19; 'work,': 0.20; 'feb': 0.22; '>>>': 0.22; 'memory': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; "aren't": 0.24; 'certainly': 0.24; 'integer': 0.24; 'fairly': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'sort': 0.25; 'define': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '(which': 0.31; 'though.': 0.31; 'this.': 0.32; 'languages': 0.32; 'supposed': 0.32; 'addresses': 0.33; 'sense': 0.34; 'could': 0.34; "can't": 0.35; 'something': 0.35; 'case,': 0.35; 'objects': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'are,': 0.36; 'object,': 0.36; 'ram': 0.36; 'subject:?': 0.36; 'performance': 0.37; 'same.': 0.38; 'handle': 0.38; 'skip:- 10': 0.38; 'does': 0.39; 'sure': 0.39; 'either': 0.39; 'ensure': 0.60; 'subject:Can': 0.60; 'simply': 0.61; "you're": 0.61; 'address': 0.63; 'face': 0.64; 'more': 0.64; 'skip:1 20': 0.65; 'guaranteed': 0.75; 'potentially': 0.81; 'distinguish': 0.84; 'improvement': 0.84; 'pike': 0.84; 'usage.': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=6u23Jcf3GZSVksph1fCkProo06BiYydxR9l85NGU/rU=; b=c0PjynxZiIY1mF1FUlVN7R/6QcW0OGcTjsQAK5JugHRLVvc+kNDHtwgbrHvJieWOcm +vc+kCkcytuoILXrSYTrtJw+v/WGLQmABHtSDM2xVda2lmVJqOlvXKnvH8OOa5TWgLAO x9rR39wNqx1xMosc+Mekm6qnn3lo5yFK8H0qfFYpjctUFU/fj0SZE8i4R0a7qYaoSJPo 9Js0Q+NFoJxVN31zWzGeKN9auhlAOUy3u0IfsMmBxtgl5Dcw1bRLSgQqMs5vIrCquJmT JEeMES8w3M/o/3aW6dCoMPSehioPuGPYwGNak4bwVsSqMyWJr0wsdAOzlflOi9Q4Rp1R +oOw== MIME-Version: 1.0 X-Received: by 10.66.102.39 with SMTP id fl7mr19648069pab.43.1393170106427; Sun, 23 Feb 2014 07:41:46 -0800 (PST) In-Reply-To: <87k3clc0n9.fsf@elektro.pacujo.net> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87sird7wuw.fsf@handshake.de> <8454E8CB-E6E3-452F-8E54-9A77BFF34EC2@gmail.com> <1m3gg9lbf2ln5m2kbki954t17mqni3b20k@4ax.com> <53095145$0$29985$c3e8da3$5496439d@news.astraweb.com> <877g8mcg1m.fsf@elektro.pacujo.net> <87ob1yay9m.fsf@elektro.pacujo.net> <87k3clc0n9.fsf@elektro.pacujo.net> Date: Mon, 24 Feb 2014 02:41:46 +1100 Subject: Re: Can global variable be passed into Python function? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393170116 news.xs4all.nl 2925 [2001:888:2000:d::a6]:60917 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66943 On Mon, Feb 24, 2014 at 2:24 AM, Marko Rauhamaa wrote: > Or id(n) =3D=3D 2 ** 64 + n for 63-bit integers; other objects get the > RAM address of the internal =E1=B8=BFemory block: > > >>> id(5) > 18446744073709551621 > >>> id([]) > 3074657068 > >>> id(id([])) > 18446744076784207372 Assuming you define "63-bit integers" either as 0<=3Dn<2**63 or as -2**62<=3Dn<2**62, this could work, but it would depend on never using memory with addresses with bit 63 set, as id() is (if I recall correctly) supposed to return an integer in the native range. I'm not sure you can depend on that sort of pattern of memory usage. In any case, you'd need some way to pretend that every integer is really an object, so you'd need to define id(), the 'is' operator, and everything else that can work with objects, to ensure that they correctly handle this. It would be a reasonable performance improvement to use native integers for the small ones (where "small" integers might still be fairly large by human standards), but unlike in languages like Pike (which does something like what you're saying), Python has a concept of "object identity" which can't be broken. (Pike's integers simply _are_, they aren't considered separate objects. You can't test them for identity. Its strings, also, simply are, although since Pike strings are guaranteed to be interned, their values and identities really are the same. To Pike, it's only more complex types that need to distinguish value from identity.) So this optimization, which certainly does make sense on the face of it, would potentially make a mess of things elsewhere. I'm sure PyPy optimizes small integers somewhat, though. ChrisA