| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- Reviewed: no -->
- <sect1 id="zend.memory.memory-manager">
- <title>Memory Manager</title>
- <sect2 id="zend.memory.memory-manager.creation">
- <title>Creating a Memory Manager</title>
- <para>
- You can create new a memory manager
- (<classname>Zend_Memory_Manager</classname> object) using the
- <methodname>Zend_Memory::factory($backendName [, $backendOprions])</methodname>
- method.
- </para>
- <para>
- The first argument <varname>$backendName</varname> is a string that
- names one of the backend implementations supported by <classname>Zend_Cache</classname>.
- </para>
- <para>
- The second argument <varname>$backendOptions</varname> is an optional
- backend options array.
- </para>
- <programlisting language="php"><![CDATA[
- $backendOptions = array(
- 'cache_dir' => './tmp/' // Directory where to put the swapped memory blocks
- );
- $memoryManager = Zend_Memory::factory('File', $backendOptions);
- ]]></programlisting>
- <para>
- <classname>Zend_Memory</classname> uses <link
- linkend="zend.cache.backends"><classname>Zend_Cache backends</classname></link> as
- storage providers.
- </para>
- <para>
- You may use the special name 'None' as a backend name,
- in addition to standard <classname>Zend_Cache</classname> backends.
- </para>
- <programlisting language="php"><![CDATA[
- $memoryManager = Zend_Memory::factory('None');
- ]]></programlisting>
- <para>
- If you use 'None' as the backend name, then the memory
- manager never swaps memory blocks. This is useful if you know that
- memory is not limited or the overall size of objects never reaches
- the memory limit.
- </para>
- <para>
- The 'None' backend doesn't need any option specified.
- </para>
- </sect2>
- <sect2 id="zend.memory.memory-manager.objects-management">
- <title>Managing Memory Objects</title>
- <para>
- This section describes creating and destroying objects in the
- managed memory, and settings to control memory manager behavior.
- </para>
- <sect3 id="zend.memory.memory-manager.objects-management.movable">
- <title>Creating Movable Objects</title>
- <para>
- Create movable objects (objects, which may be swapped) using
- the <methodname>Zend_Memory_Manager::create([$data])</methodname> method:
- </para>
- <programlisting language="php"><![CDATA[
- $memObject = $memoryManager->create($data);
- ]]></programlisting>
- <para>
- The <varname>$data</varname> argument is optional and used to
- initialize the object value. If the <varname>$data</varname>
- argument is omitted, the value is an empty string.
- </para>
- </sect3>
- <sect3 id="zend.memory.memory-manager.objects-management.locked">
- <title>Creating Locked Objects</title>
- <para>
- Create locked objects (objects, which are not swapped) using
- the <methodname>Zend_Memory_Manager::createLocked([$data])</methodname> method:
- </para>
- <programlisting language="php"><![CDATA[
- $memObject = $memoryManager->createLocked($data);
- ]]></programlisting>
- <para>
- The <varname>$data</varname> argument is optional and used to
- initialize the object value. If the <varname>$data</varname>
- argument is omitted, the value is an empty string.
- </para>
- </sect3>
- <sect3 id="zend.memory.memory-manager.objects-management.destruction">
- <title>Destroying Objects</title>
- <para>
- Memory objects are automatically destroyed and removed from
- memory when they go out of scope:
- </para>
- <programlisting language="php"><![CDATA[
- function foo()
- {
- global $memoryManager, $memList;
- ...
- $memObject1 = $memoryManager->create($data1);
- $memObject2 = $memoryManager->create($data2);
- $memObject3 = $memoryManager->create($data3);
- ...
- $memList[] = $memObject3;
- ...
- unset($memObject2); // $memObject2 is destroyed here
- ...
- // $memObject1 is destroyed here
- // but $memObject3 object is still referenced by $memList
- // and is not destroyed
- }
- ]]></programlisting>
- <para>
- This applies to both movable and locked objects.
- </para>
- </sect3>
- </sect2>
- <sect2 id="zend.memory.memory-manager.settings">
- <title>Memory Manager Settings</title>
- <sect3 id="zend.memory.memory-manager.settings.memory-limit">
- <title>Memory Limit</title>
- <para>
- Memory limit is a number of bytes allowed to be used by loaded
- movable objects.
- </para>
- <para>
- If loading or creation of an object causes memory usage to
- exceed of this limit, then the memory manager swaps some other
- objects.
- </para>
- <para>
- You can retrieve or set the memory limit setting using the
- <methodname>getMemoryLimit()</methodname> and
- <methodname>setMemoryLimit($newLimit)</methodname> methods:
- </para>
- <programlisting language="php"><![CDATA[
- $oldLimit = $memoryManager->getMemoryLimit(); // Get memory limit in bytes
- $memoryManager->setMemoryLimit($newLimit); // Set memory limit in bytes
- ]]></programlisting>
- <para>
- A negative value for memory limit means 'no limit'.
- </para>
- <para>
- The default value is two-thirds of the value of
- 'memory_limit' in php.ini or 'no limit' (-1)
- if 'memory_limit' is not set in php.ini.
- </para>
- </sect3>
- <sect3 id="zend.memory.memory-manager.settings.min-size">
- <title>MinSize</title>
- <para>
- MinSize is a minimal size of memory objects, which may be
- swapped by memory manager. The memory manager does not swap
- objects that are smaller than this value. This reduces the
- number of swap/load operations.
- </para>
- <para>
- You can retrieve or set the minimum size using the
- <methodname>getMinSize()</methodname> and
- <methodname>setMinSize($newSize)</methodname> methods:
- </para>
- <programlisting language="php"><![CDATA[
- $oldMinSize = $memoryManager->getMinSize(); // Get MinSize in bytes
- $memoryManager->setMinSize($newSize); // Set MinSize limit in bytes
- ]]></programlisting>
- <para>
- The default minimum size value is 16KB (16384 bytes).
- </para>
- </sect3>
- </sect2>
- </sect1>
|