Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59428 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45514 invoked from network); 7 Apr 2012 16:51:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Apr 2012 16:51:31 -0000 Authentication-Results: pb1.pair.com header.from=luke@cywh.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=luke@cywh.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain cywh.com from 209.85.212.42 cause and error) X-PHP-List-Original-Sender: luke@cywh.com X-Host-Fingerprint: 209.85.212.42 mail-vb0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:50253] helo=mail-vb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7F/6B-23111-290708F4 for ; Sat, 07 Apr 2012 12:51:31 -0400 Received: by vbjk13 with SMTP id k13so1945811vbj.29 for ; Sat, 07 Apr 2012 09:51:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=references:from:in-reply-to:mime-version:date:message-id:subject:to :cc:content-type:x-gm-message-state; bh=SD25UW0zmS2sY3ODu+B2t2ALRczwWzLe+tfYXAvv660=; b=p4jiB6K4+X2opuFWt7bBbJUq9Fj/JnhVgASsv0akO3pqk8nexOfMyFgI+zBfLHQXef l6vTYF+vJ0OcMkHt4AR3NiNSoKkIyw3F7iJDZhYKH4fhZcD2AaQmqgDWkibHjW6vqNOi YDDf9GT2+8+uTL8LUiv5j9WfOUQtQMmGnmteWrekRfxjHt370RQn+VR505NvsjJohrMh gy1MZ3jG5A7LZef8fqkrkcoAoHE2Na/DLWhteRlj5lOxrdephojJYsoMGFccUHyT92Ng 9t83Q0qAAHNg+8PMurJmVHZ4GcV1EgLRm/KDz1Kp4O/CVKrONDdhqczCDLIibrlBLSPA 7J0A== Received: by 10.52.178.225 with SMTP id db1mr538083vdc.26.1333817487864; Sat, 07 Apr 2012 09:51:27 -0700 (PDT) References: <11343239.3338.1333757773882.JavaMail.mobile-sync@iakr3> <1722329293808329363@unknownmsgid> <4F7FD377.9030207@sugarcrm.com> In-Reply-To: <4F7FD377.9030207@sugarcrm.com> Mime-Version: 1.0 (1.0) Date: Sat, 7 Apr 2012 09:51:26 -0700 Message-ID: <-8675298664786638901@unknownmsgid> To: Stas Malyshev Cc: PHP Internals Content-Type: text/plain; charset=ISO-8859-1 X-Gm-Message-State: ALoCoQmEoDk/kUb29fEgOQ54T3vPDprFfdBUcArfB3R0gcR+JCwzCM4lfe8ryBxm7vHKfqprhcvQ Subject: Re: [PHP-DEV] Persistent zvals From: luke@cywh.com (Luke Scott) On Apr 6, 2012, at 10:41 PM, Stas Malyshev wrote: > Hi! > >> How is memory tracked with emalloc? From my observations anything >> created with emalloc, with or without a zval wrapper, is freed at the >> end of the request. Things created with pemalloc, which seems to be a >> wrapper of malloc, isn't thrown away. > > Zend Engine has its own memory manager, see zend_alloc.c. Unfortunately, > I'm not sure I'll be able to explain in short how it works, but TLDR > version of it is that it's like malloc, but private to Zend Engine, so > everything is freed at the end of the request. > >> From what I've seen this is because the zvals, the values inside, the >> object bucket, etc... is all created by emalloc. Correct me if I'm >> wrong, but even if i could persist the zval (wrapper) the value inside >> would be freed unless both the zval and the value were created with >> pemalloc (alias of malloc). It goes a step further with the objects >> because a zend_object is just a handle ID (pointing to a spot in the >> bucket) and a pointer to object handlers. > > This is correct, all internal memory allocations are done by emalloc. > zend_object, however, is not just a handle - this handle refers to > object structure, which has class pointer, properties, etc. > >> and not much better than serialization. I'd like to avoid copying >> memory if possible. A flag on the zval would be ideal. > > That's what I am trying to explain - flag on one zval would not help > you, since this zval uses dozens, if not hundreds (for bigger object) > other resources, including other zvals, hashtables, object structures, > class structures, function structures, etc. etc. > Add to that that if you allocated something in emalloc arena you can not > just mark it "do not free it" - that would create a huge fragmentation > problem if you had something non-freeable at the middle of freeable > region. So you can not just "flag" random variable as non-freeable > without messing up whole memory manager (btw, not advisable with malloc > either - fragmentation can inflate you memory usage very easily). Not > that it would work even if you could, see above. I think I understand what you're getting at. So to avoid fragmentation you would have to have two independent memory spaces. Making non persistent memory persistent would require copying from one space to another. Is that correct? How is this handled in other platforms where you have an application instance (with state, if that's the correct terminology)? Are there any other options for reliably persisting objects/variables (without having to recreate)? (Re-sending to the list) > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > (408)454-6900 ext. 227