Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112734 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 1355 invoked from network); 3 Jan 2021 18:07:42 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Jan 2021 18:07:42 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2BA31180503 for ; Sun, 3 Jan 2021 09:43:26 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-oln040092005091.outbound.protection.outlook.com [40.92.5.91]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 3 Jan 2021 09:43:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k78f3pgqPsARzoj1ZYtbO5yehixUGfZequkJQoEFwi5keRHGLlXVcuDhFZLf3g5G8MbIZ16X89f1nHQlzsPamvOFUuGUTUxMtLb3KlFb17GXNT+Muz2ceKSi48+b8gxAm+F2ZwUWeRhFuvOuNV/Kg4W4TcxQoJTzzIJQYltuNMZuIqJ81YWN3DRnv8UkMulHbF5JKQJkj84lw78TpRZsAtm146ufhB9FnvYavxZiGnXds/6yDN7G3BjflsWfUceOjeeSZb/UT6RWaeGZL7nVyF6eYh99AkA11q6RYSXd34tQmyBBCuM2G93NXSsD5VcBIjSDtwPvHnW6xGlSRLSX5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Mkn/v39RhihXTJeQLPkoN9WoHmozSa+JBO8ysuSsx8Y=; b=KNeCEsV0ZzTNCa1R0XjIuOo+e9sl0mTOMxt1it3a/c2/3NoUlsGUJEgSEnoPC2ln5C7F2BRT1yIfG5KFSwKvvDYuQLRIPUf4bvkh60NIs/+4j27PL9ObdrwSA4iwqOlerk6naBAIDSjys3h0eGELCx7jEwtR1zmoHg+TmFa8Pkb6fpHEL26POuNbOwQZ7z39ZdfTCLJ8snrz0KFf0Yu7n5GaeJjJKqCLGjv04RbJL1sXjBoOI3bR7IJfLms6FnXbagbkPGIH+QBqlaOQo9va2vVwgvI0zeNEkFFkyyk7QMv2Hw+SfAH8PzN9HXrK/hgk6O6w8c2Zd3krjOYcsjHFeQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Mkn/v39RhihXTJeQLPkoN9WoHmozSa+JBO8ysuSsx8Y=; b=dIeEsGUXVBApriGlwYZ7XPbMqbTG0ZSlHNWhwhRoeSl2bCKNerb4RgYuMzqW406p0fe+DH0acoysk7deEQ14wcRgfcoTsg8dG5pu7S5ZCtZIVb5t+G2H8MGD/31rJT1nHeQx9ER7GYTa0gE7M/jnyIhLHegJHDy19iWRQlNUWx4j/5fHeUqeXaA0rlz1ifvLPYQijlV0u0RWE4B1WFwMtRHKwuiIDIfrKPoO6Rbzo9ip+1jDvfFjiWi/bXu5ZtQ8auAn2nOWY/7IyZ065EldjhAsyMVeJOAe7xYKzfg5jaCEids1D2FgBkiXNV06BMLB8dgCGLl0ot/3VuGr+8DKPg== Received: from CY1NAM02FT064.eop-nam02.prod.protection.outlook.com (10.152.74.58) by CY1NAM02HT207.eop-nam02.prod.protection.outlook.com (10.152.75.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.22; Sun, 3 Jan 2021 17:43:24 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:7e45::51) by CY1NAM02FT064.mail.protection.outlook.com (2a01:111:e400:7e45::64) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.22 via Frontend Transport; Sun, 3 Jan 2021 17:43:24 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::b4c4:dc11:5337:821d]) by DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::b4c4:dc11:5337:821d%4]) with mapi id 15.20.3721.024; Sun, 3 Jan 2021 17:43:24 +0000 To: =?Windows-1252?Q?Olle_H=E4rstedt?= , Sara Golemon CC: PHP internals Thread-Topic: [PHP-DEV] Does PHP ever stack allocate? Thread-Index: AQHW4IOsrfZREM6ffE6PJsMMA0l0PqoWFjAAgAAGVQCAAAG1+A== Date: Sun, 3 Jan 2021 17:43:24 +0000 Message-ID: References: , In-Reply-To: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:D282DCA4AF5BFF74D972C25CBFEFACEBA9A68079CF4A144A7C587C81696B1A4D;UpperCasedChecksum:38BC10019601BBA1CCCB33442A2339ADB9638952DFCD47FB0E4DCD23D5D9EE13;SizeAsReceived:7113;Count:45 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [Dere2qv7Xk/O5XQI3IU4tsbbYdQky3lPFBbwwOrAlr0=] x-ms-publictraffictype: Email x-incomingheadercount: 45 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 27759efd-3ea6-47ae-2b0f-08d8b00f11cb x-ms-traffictypediagnostic: CY1NAM02HT207: x-ms-exchange-minimumurldomainage: segment.com#8217 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: zNyp37mT74e0r8qj5hNNBWbtpEGJEnvC8BW5Hp7OYZhBbl2vFt0SS46qUA2wHQFYjKxLU4pctFVguUhOeUisNsGET1yer5S1Tejz9+zAN0HdrZ8heEMVq4L1W2x+aJaBTB1V2RByQVV/5r2LJ5hvydgpuhgCggpHEia0YtUduBG+13kM9bI6ShKqAppnmeM/j+zLc05X0kLQRU0M7NvMy15QL178b4rQICXAlTN4GtjGSh7mmeL5KIPPv4wEaIGApDfwzSKxaTd+6a9LNd4e658Tv/TNOTWkRXugtMlXtcc= x-ms-exchange-antispam-messagedata: SlxjLrVAG3fD9hM50c5cj4vDL14eC2ZmmODooN4Lnp3JBv5eaBxzNiGCkZzuQgivJGoXDzZ00d5CGgQh9ljAswF8aN3bPc5cGRi4lTYeB2yvKGR3VHdqlVSG1wOEEDURDqXFku8HDSVuJ9PkhL8FRw== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-AuthSource: CY1NAM02FT064.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 27759efd-3ea6-47ae-2b0f-08d8b00f11cb X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Jan 2021 17:43:24.2090 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1NAM02HT207 Subject: Re: [PHP-DEV] Does PHP ever stack allocate? From: tysonandre775@hotmail.com (tyson andre) Hi Olle,=0A= =0A= > Thanks Sara! I realize I should have been more precise: Can PHP=0A= > allocate non-reference counted memory that automatically is freed when=0A= > leaving scope, similar to what Go does with escape analysis?=0A= >=0A= > Article describing the Go mechanism:=0A= > https://segment.com/blog/allocation-efficiency-in-high-performance-go-ser= vices/=0A= =0A= Could you give some concrete examples of what type of code you're talking a= bout?=0A= As Sara Golemon said, scalars (null, bool, int, float) are allocated on a p= hp call frame,=0A= and the call frames go on a stack. That stack is separate from the C stack,= but still a stack=0A= =0A= The call frame is "freed" when leaving scope - i.e. that part of the stack = will be reused on subsequent calls.=0A= =0A= > A single PHP call frame holds a block of storage space for (among other= =0A= > things) all* local variables. This can be thought of analogously to "the= =0A= > stack" as it's used by native applications. Basic scalars (null, bool,= =0A= > int, float) sit in this space with no additional pointers to anywhere.=0A= > Non-scalars use pointers to elsewhere in the heap to store the actual=0A= > payload. This isn't unique to PHP, as these structures have runtime=0A= > determined size and thus can't** be stack allocated.=0A= =0A= https://nikic.github.io/2017/04/14/PHP-7-Virtual-machine.html may help if y= ou want to learn more about what the PHP VM currently does=0A= =0A= > So what=92s the difference between TMP and VAR? Not much.=0A= > The distinction was inherited from PHP 5, where TMPs were VM stack alloca= ted,=0A= > while VARs were heap allocated. In PHP 7 all variables are stack allocate= d.=0A= > As such, nowadays the main difference between TMPs and VARs is that only = the latter are allowed to contain REFERENCEs=0A= > (this allows us to elide DEREFs on TMPs). Furthermore VARs may hold two t= ypes of special values,=0A= > namely class entries and INDIRECT values. The latter are used to handle n= on-trivial assignments.=0A= =0A= -Tyson=