You should take care not to mistake the GC and the MM, they are two
different things and surprisingly, they dont interact with each other.
Zend GC is a layer above Zend MM, and Zend GC can be totally disabled,
Zend MM cant at all.

Zend MM is a BIG layer over malloc()/free() which goals are mainly to
abstract the OS MM (mainly Unix/Win32) and to avoid memory
fragmentation and too many system calls which could lead to
performance problems. Lots of other programms use such a tool, like
Apache httpd for example.

Zend MM can also help you (in debug mode only) by showing its state
after a script has run, alowing you to easily track memory leaks while
using it (e**() functions) without the need to use tools such as
valgrind.
ZendMM can track all the PHP memory usage, and provide feature such as
"memory_limit".

Finally, ZendMM is a super malloc(), it nearly can be foreseen as a
custom implementation of libc malloc() using a heap over the heap and
trying to optimize it as possible.

Simply looking at the structs in zend_alloc.h let you guess it's goal,
but you need to know how memory management works in computer programs
for that.

Julien.P



On Wed, Feb 2, 2011 at 7:52 AM, Adi Mutu <adi_mut...@yahoo.com> wrote:
>
> Thanks a lot, for all the help about zend mm guys,  i'm very grateful.
> Thanks,A.
>
> --- On Sun, 1/30/11, Ben Schmidt <mail_ben_schm...@yahoo.com.au> wrote:
>
> From: Ben Schmidt <mail_ben_schm...@yahoo.com.au>
> Subject: Re: [PHP-DEV] Re: Zend mm
> To: "Adi Mutu" <adi_mut...@yahoo.com>
> Cc: internals@lists.php.net, t...@daylessday.org
> Date: Sunday, January 30, 2011, 4:45 PM
>
> On 30/01/11 4:11 AM, Adi Mutu wrote:
>> I have looked at the sources, but i'm only at the begining of
>> analyzing the php sources.....i've understand how to write extensions
>> for example, but this memory manager seems more complicated to me.....
>
> Yes, it is. Memory management is a low-level and subtle area. It takes a
> lot of careful thought to design and even to understand the algorithms
> involved. It is hard to debug, because an error caused in one place may
> not show itself until completely different code is executing. It is also
> an area which doesn't change much. Almost all the other code in the PHP
> interpreter, and therefore PHP scripts themselves, rely on the memory
> manager code doing its job unintrusively and correctly, so once it is
> working well, it tends to be left that way, except for fixing small bugs
> as they are found, or a big and careful development effort to address
> some limitation (e.g. improving the garbage collection to collect
> cycles, which was something done fairly recently).
>
> The bottom line is that this is not an area that is all that easy for
> beginners to get their teeth into. But it's also an area that isn't
> necessary for beginners to understand in much detail, either. Unless you
> have a particular project in mind that involves the memory manager, you
> probably don't need to touch it.
>
> I don't want to discourage you, but just point out that perhaps this is
> something you might look at later, or even not at all, as you may find
> there are many worthwhile projects that take up all your time before you
> ever get to understanding the memory manager fully.
>
>> It would be useful if for example, could explain me the structures
>> that are used in the Zend memory manager, how they're chained
>> etc.....and if you can tell me in words what do zend_mm_aloc_int() and
>> zend_mm_free_int() basically do...Thank you for your time,Adrian
>
> I suspect these structures and functions are fairly easy to understand
> by someone familiar with the area of memory management, which is why you
> have been advised to consult the source code. So perhaps what you need
> to do is not learn about PHP's memory manager, but just learn about
> memory management in general. Then it should be fairly easy to
> understand what PHP's memory manager is doing from its code.
>
> I'm afraid I doubt the people here have the time to teach you this over
> email. :-) So here are some references which might be of use to you.
>
> - I believe the 'standard textbook' for learning about memory management
>   is this one here:
>   http://www.cs.kent.ac.uk/people/staff/rej/gcbook/gcbook.html
>
> - This page also mentions that a new edition is due out soon:
>   http://c2.com/cgi/wiki?GarbageCollectionBook
>
> - You can also check out this site: http://www.memorymanagement.org/
>
> - Relating this to, PHP: PHP is a garbage collected language which I
>   believe uses reference counting and a clever collector to detect and
>   free cycles. I haven't looked in detail into the implementation, but I
>   know some documentation is available on the subject here:
>   http://www.php.net/manual/en/features.gc.php
>
> Hope this helps!
>
> Ben.
>
>
>
>
>
>
>

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to