Zend_Memory-MemoryManager.xml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.memory.memory-manager">
  4. <title>Memory Manager</title>
  5. <sect2 id="zend.memory.memory-manager.creation">
  6. <title>Creating a Memory Manager</title>
  7. <para>
  8. You can create new a memory manager
  9. (<classname>Zend_Memory_Manager</classname> object) using the
  10. <methodname>Zend_Memory::factory($backendName [, $backendOprions])</methodname>
  11. method.
  12. </para>
  13. <para>
  14. The first argument <varname>$backendName</varname> is a string that
  15. names one of the backend implementations supported by <classname>Zend_Cache</classname>.
  16. </para>
  17. <para>
  18. The second argument <varname>$backendOptions</varname> is an optional
  19. backend options array.
  20. </para>
  21. <programlisting language="php"><![CDATA[
  22. $backendOptions = array(
  23. 'cache_dir' => './tmp/' // Directory where to put the swapped memory blocks
  24. );
  25. $memoryManager = Zend_Memory::factory('File', $backendOptions);
  26. ]]></programlisting>
  27. <para>
  28. <classname>Zend_Memory</classname> uses <link
  29. linkend="zend.cache.backends"><classname>Zend_Cache backends</classname></link> as
  30. storage providers.
  31. </para>
  32. <para>
  33. You may use the special name 'None' as a backend name,
  34. in addition to standard <classname>Zend_Cache</classname> backends.
  35. </para>
  36. <programlisting language="php"><![CDATA[
  37. $memoryManager = Zend_Memory::factory('None');
  38. ]]></programlisting>
  39. <para>
  40. If you use 'None' as the backend name, then the memory
  41. manager never swaps memory blocks. This is useful if you know that
  42. memory is not limited or the overall size of objects never reaches
  43. the memory limit.
  44. </para>
  45. <para>
  46. The 'None' backend doesn't need any option specified.
  47. </para>
  48. </sect2>
  49. <sect2 id="zend.memory.memory-manager.objects-management">
  50. <title>Managing Memory Objects</title>
  51. <para>
  52. This section describes creating and destroying objects in the
  53. managed memory, and settings to control memory manager behavior.
  54. </para>
  55. <sect3 id="zend.memory.memory-manager.objects-management.movable">
  56. <title>Creating Movable Objects</title>
  57. <para>
  58. Create movable objects (objects, which may be swapped) using
  59. the <methodname>Zend_Memory_Manager::create([$data])</methodname> method:
  60. </para>
  61. <programlisting language="php"><![CDATA[
  62. $memObject = $memoryManager->create($data);
  63. ]]></programlisting>
  64. <para>
  65. The <varname>$data</varname> argument is optional and used to
  66. initialize the object value. If the <varname>$data</varname>
  67. argument is omitted, the value is an empty string.
  68. </para>
  69. </sect3>
  70. <sect3 id="zend.memory.memory-manager.objects-management.locked">
  71. <title>Creating Locked Objects</title>
  72. <para>
  73. Create locked objects (objects, which are not swapped) using
  74. the <methodname>Zend_Memory_Manager::createLocked([$data])</methodname> method:
  75. </para>
  76. <programlisting language="php"><![CDATA[
  77. $memObject = $memoryManager->createLocked($data);
  78. ]]></programlisting>
  79. <para>
  80. The <varname>$data</varname> argument is optional and used to
  81. initialize the object value. If the <varname>$data</varname>
  82. argument is omitted, the value is an empty string.
  83. </para>
  84. </sect3>
  85. <sect3 id="zend.memory.memory-manager.objects-management.destruction">
  86. <title>Destroying Objects</title>
  87. <para>
  88. Memory objects are automatically destroyed and removed from
  89. memory when they go out of scope:
  90. </para>
  91. <programlisting language="php"><![CDATA[
  92. function foo()
  93. {
  94. global $memoryManager, $memList;
  95. ...
  96. $memObject1 = $memoryManager->create($data1);
  97. $memObject2 = $memoryManager->create($data2);
  98. $memObject3 = $memoryManager->create($data3);
  99. ...
  100. $memList[] = $memObject3;
  101. ...
  102. unset($memObject2); // $memObject2 is destroyed here
  103. ...
  104. // $memObject1 is destroyed here
  105. // but $memObject3 object is still referenced by $memList
  106. // and is not destroyed
  107. }
  108. ]]></programlisting>
  109. <para>
  110. This applies to both movable and locked objects.
  111. </para>
  112. </sect3>
  113. </sect2>
  114. <sect2 id="zend.memory.memory-manager.settings">
  115. <title>Memory Manager Settings</title>
  116. <sect3 id="zend.memory.memory-manager.settings.memory-limit">
  117. <title>Memory Limit</title>
  118. <para>
  119. Memory limit is a number of bytes allowed to be used by loaded
  120. movable objects.
  121. </para>
  122. <para>
  123. If loading or creation of an object causes memory usage to
  124. exceed of this limit, then the memory manager swaps some other
  125. objects.
  126. </para>
  127. <para>
  128. You can retrieve or set the memory limit setting using the
  129. <methodname>getMemoryLimit()</methodname> and
  130. <methodname>setMemoryLimit($newLimit)</methodname> methods:
  131. </para>
  132. <programlisting language="php"><![CDATA[
  133. $oldLimit = $memoryManager->getMemoryLimit(); // Get memory limit in bytes
  134. $memoryManager->setMemoryLimit($newLimit); // Set memory limit in bytes
  135. ]]></programlisting>
  136. <para>
  137. A negative value for memory limit means 'no limit'.
  138. </para>
  139. <para>
  140. The default value is two-thirds of the value of
  141. 'memory_limit' in php.ini or 'no limit' (-1)
  142. if 'memory_limit' is not set in php.ini.
  143. </para>
  144. </sect3>
  145. <sect3 id="zend.memory.memory-manager.settings.min-size">
  146. <title>MinSize</title>
  147. <para>
  148. MinSize is a minimal size of memory objects, which may be
  149. swapped by memory manager. The memory manager does not swap
  150. objects that are smaller than this value. This reduces the
  151. number of swap/load operations.
  152. </para>
  153. <para>
  154. You can retrieve or set the minimum size using the
  155. <methodname>getMinSize()</methodname> and
  156. <methodname>setMinSize($newSize)</methodname> methods:
  157. </para>
  158. <programlisting language="php"><![CDATA[
  159. $oldMinSize = $memoryManager->getMinSize(); // Get MinSize in bytes
  160. $memoryManager->setMinSize($newSize); // Set MinSize limit in bytes
  161. ]]></programlisting>
  162. <para>
  163. The default minimum size value is 16KB (16384 bytes).
  164. </para>
  165. </sect3>
  166. </sect2>
  167. </sect1>