Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #97077

Re: Idiosyncratic python

Path csiph.com!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
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; 'value,': 0.03; 'caller': 0.07; 'option,': 0.07; 'malloc': 0.09; 'naturally': 0.09; 'python': 0.10; 'python.': 0.11; 'stack': 0.13; 'subject:python': 0.14; 'thu,': 0.15; 'weird': 0.15; '24,': 0.16; 'fits': 0.16; 'heap': 0.16; 'jmp': 0.16; 'pointer,': 0.16; 'wrote:': 0.16; 'memory': 0.17; 'pointer': 0.18; 'creates': 0.18; 'variable': 0.18; '2015': 0.20; 'context.': 0.22; 'expense': 0.22; 'sep': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'sense': 0.26; 'message-id:@mail.gmail.com': 0.27; 'allocated': 0.27; 'function': 0.28; 'pointer.': 0.29; 'option': 0.31; 'returned': 0.32; 'structure': 0.34; 'gives': 0.35; 'received:google.com': 0.35; 'but': 0.36; 'structures': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'copying': 0.38; 'data': 0.39; 'takes': 0.39; 'to:addr:python.org': 0.40; 'provide': 0.61; 'course': 0.62; 'leaving': 0.63; 'within': 0.64; 'to:name:python': 0.84; 'habit': 0.91; 'leak': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=3qgsfbh5oEZ6Qm7NUuCOuNNwIXWLTIwvWN800v4ahXY=; b=AADXAGlszd+Onao/49Z9LEeWNqPGdinLoMRBJQqwpxryRMwNk485AntatdApfdFicy GYmDd/qZzeGEp1v6RBd4E4KXN20o4CI8JSnAO91ptu9Dvea+XUhLRUopq3LWvynXTguR ClwFsM0MrYjruL1pY9OV5m+CWeBEHlVkU0d6jCiDuF+iZZW3pBjDGMyb7BhD31HaxRl7 Af4ZE7Icpvymw0gQk4oIMRf6U/yxTD8s/0XnZun481ycREenuJy+YpROP72aGt9waOmE VzDpohUYbWXXzQxSQD6Te3WFT9DJwm30KULidDk3LnTM78zheWKJQpYmRVnHMBKVFMM/ aDNQ==
X-Received by 10.170.194.22 with SMTP id l22mr29453372yke.63.1443104810683; Thu, 24 Sep 2015 07:26:50 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <mu102h$2oh$1@ger.gmane.org>
References <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> <mu0eq4$2d2$1@ger.gmane.org> <CAJ4+4aoDY30HmhNrOjG2g+ODoS1vSOMtuANXp0unbuwWcuQd3g@mail.gmail.com> <mu102h$2oh$1@ger.gmane.org>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Thu, 24 Sep 2015 08:26:11 -0600
Subject Re: Idiosyncratic python
To Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.130.1443104819.28679.python-list@python.org> (permalink)
Lines 18
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1443104819 news.xs4all.nl 23819 [2001:888:2000:d::a6]:58951
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:97077

Show key headers only | View raw


On Thu, Sep 24, 2015 at 8:07 AM, jmp <jeanmichel@sequans.com> wrote:
> result = getResult()
>
> For the later, the original weird form come from a C habit to allocate
> returned structures within the caller and provide a pointer to it so the
> function can fill the data in, otherwise the structure is lost as the stack
> is popped out and the structure content is garbage. None of this make any
> sense in python.

Only if the structure is allocated on the stack and returned by
pointer. If it's returned by value, then the content remains intact,
but at the expense of copying it. The other option of course would be
to allocate it on the heap and return the pointer, but this needlessly
incurs malloc overhead and creates an opportunity for a memory leak if
the variable is naturally stack-scoped. Python effectively takes this
option, as everything is allocated on the heap. Leaving it up to the
caller to provide a pointer also gives the caller the option of
allocating on the stack or the heap as best fits the context.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Idiosyncratic python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-09-24 16:02 +1000
  Re: Idiosyncratic python Paul Rubin <no.email@nospam.invalid> - 2015-09-23 23:16 -0700
    Re: Idiosyncratic python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-09-24 16:35 +1000
      Re: Idiosyncratic python Ben Finney <ben+python@benfinney.id.au> - 2015-09-24 16:54 +1000
        Re: Idiosyncratic python Steven D'Aprano <steve@pearwood.info> - 2015-09-25 11:08 +1000
      Re: Idiosyncratic python Terry Reedy <tjreedy@udel.edu> - 2015-09-24 02:54 -0400
  Re: Idiosyncratic python wxjmfauth@gmail.com - 2015-09-24 00:06 -0700
    Re: Idiosyncratic python Laurent Pointal <laurent.pointal@free.fr> - 2015-09-24 19:50 +0200
      Re: Idiosyncratic python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-24 21:05 +0100
  Re: Idiosyncratic python jmp <jeanmichel@sequans.com> - 2015-09-24 11:12 +0200
  Re: Idiosyncratic python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-24 14:09 +0100
  Re: Idiosyncratic python jmp <jeanmichel@sequans.com> - 2015-09-24 16:07 +0200
  Re: Idiosyncratic python Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-24 08:26 -0600
  Re: Idiosyncratic python Chris Angelico <rosuav@gmail.com> - 2015-09-25 02:57 +1000
  Re: Idiosyncratic python jmp <jeanmichel@sequans.com> - 2015-09-24 20:04 +0200
  Re: Idiosyncratic python Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-24 12:19 -0600
  Re: Idiosyncratic python Ned Batchelder <ned@nedbatchelder.com> - 2015-09-24 13:46 -0700
    Re: Idiosyncratic python Laura Creighton <lac@openend.se> - 2015-09-24 23:08 +0200
    Re: Idiosyncratic python Chris Angelico <rosuav@gmail.com> - 2015-09-25 07:49 +1000
    Re: Idiosyncratic python Steven D'Aprano <steve@pearwood.info> - 2015-09-25 10:55 +1000
  Re: Idiosyncratic python sohcahtoa82@gmail.com - 2015-09-24 15:32 -0700
  Re: Idiosyncratic python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-25 00:40 +0100
  Re: Idiosyncratic python Akira Li <4kir4.1i@gmail.com> - 2015-09-25 03:04 +0300
  Re: Idiosyncratic python Steven D'Aprano <steve@pearwood.info> - 2015-09-25 10:08 +1000

csiph-web