Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:19544 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13861 invoked by uid 1010); 10 Oct 2005 08:50:08 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 13846 invoked from network); 10 Oct 2005 08:50:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Oct 2005 08:50:08 -0000 X-Host-Fingerprint: 212.217.248.17 radio.skycom.se Linux 2.5 (sometimes 2.4) (4) Received: from ([212.217.248.17:51433] helo=radio.skycom.se) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id F0/52-54476-D3B2A434 for ; Mon, 10 Oct 2005 04:50:05 -0400 Received: from localhost (localhost [127.0.0.1]) by radio.skycom.se (Postfix) with ESMTP id 15B786009963; Mon, 10 Oct 2005 10:48:07 +0200 (CEST) Received: from radio.skycom.se ([127.0.0.1]) by localhost (radio [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 11340-05; Mon, 10 Oct 2005 10:48:06 +0200 (CEST) Received: from [10.0.0.82] (87.183.32.ip.nordiq.net [212.32.183.87]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by radio.skycom.se (Postfix) with ESMTP id 8C7086009965; Mon, 10 Oct 2005 10:48:06 +0200 (CEST) Message-ID: <434A2B43.7020608@vimio.com> Date: Mon, 10 Oct 2005 10:50:11 +0200 User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Sara Golemon Cc: internals@lists.php.net References: <4A.46.54476.C2272434@pb1.pair.com> <002801c5c8fe$b62d2ef0$6d561a44@lighthammer> <8F.35.54476.F96D4434@pb1.pair.com> <002f01c5caa1$da4f1b50$ad6c0646@lighthammer> In-Reply-To: <002f01c5caa1$da4f1b50$ad6c0646@lighthammer> Content-Type: multipart/mixed; boundary="------------020606000107020105020904" X-Virus-Scanned: amavisd-new at example.com Subject: Re: zval "passthrough"? From: david.olsson@vimio.com (David Olsson) --------------020606000107020105020904 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit > Normal userspace variables (zvals) are allocated "non-persistently". > This means that, for example, creating a string variable consists of > emalloc() calls: > > foo = emalloc(sizeof(zval)); > foo->value.str.val = emalloc(sizeof("bar")); > > emalloc()'d pointers are forcibly freed between requests (as part of > Zend's garbage collection), so even though you've taken care of all > the other bits or placing the zval* into your map in regards to > reference counting and creating a true copy, the zval itself is > allocated non-persistently and will be quietly killed by the engine at > the end of your request. (Well, no so quietly if you have > --enable-debug turned on). So that means that all the zval * I store in my map simply point to invalid memory once the request is completed? Well, that would explain some of the strange behaviour I have observed (such as string changing content between requests). The solution to this would be to allocate the zval struct using pemalloc and allocate memory for the data the zval (whatever type it is) uses with pemalloc as well? > > In order to hold a zval between requests you'll have to make a > persistent copy of it (using pemalloc() which, I'm afraid, is a bit > more complicated than it sounds). Take a look at apc_store() and > apc_fetch() which do...well....pretty much what you're talking about > here. > As far as I can tell, the APC extension doesn't use pemalloc but rather malloc. Furthermore, pemalloc simply seems to be a macro which uses malloc to allocate memory. This means that my memory allocations using c++ new should allocate persistent memory chunks. So the persistent/non-persistent memory issue doesn't explain why my std::map simply is empty. The fact that it contain zval pointers pointing to invalid memory I understand but I don't get why it gets emptied. Any ideas? Best regards David Olsson --------------020606000107020105020904--