Zend_Memory-MemoryManager.xml 7.1 KB

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