1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.memory.memory-manager">
4 <title>Memory Manager</title>
6 <sect2 id="zend.memory.memory-manager.creation">
7 <title>Creating a Memory Manager</title>
10 You can create new a memory manager
11 (<classname>Zend_Memory_Manager</classname> object) using the
12 <methodname>Zend_Memory::factory($backendName [, $backendOprions])</methodname>
17 The first argument <varname>$backendName</varname> is a string that
18 names one of the backend implementations supported by <classname>Zend_Cache</classname>.
22 The second argument <varname>$backendOptions</varname> is an optional
23 backend options array.
26 <programlisting language="php"><![CDATA[
27 $backendOptions = array(
28 'cache_dir' => './tmp/' // Directory where to put the swapped memory blocks
31 $memoryManager = Zend_Memory::factory('File', $backendOptions);
35 <classname>Zend_Memory</classname> uses <link
36 linkend="zend.cache.backends"><classname>Zend_Cache backends</classname></link> as
41 You may use the special name '<code>None</code>' as a backend name,
42 in addition to standard <classname>Zend_Cache</classname> backends.
45 <programlisting language="php"><![CDATA[
46 $memoryManager = Zend_Memory::factory('None');
50 If you use '<code>None</code>' as the backend name, then the memory
51 manager never swaps memory blocks. This is useful if you know that
52 memory is not limited or the overall size of objects never reaches
57 The '<code>None</code>' backend doesn't need any option specified.
61 <sect2 id="zend.memory.memory-manager.objects-management">
62 <title>Managing Memory Objects</title>
65 This section describes creating and destroying objects in the
66 managed memory, and settings to control memory manager behavior.
69 <sect3 id="zend.memory.memory-manager.objects-management.movable">
70 <title>Creating Movable Objects</title>
73 Create movable objects (objects, which may be swapped) using
74 the <methodname>Zend_Memory_Manager::create([$data])</methodname> method:
77 <programlisting language="php"><![CDATA[
78 $memObject = $memoryManager->create($data);
82 The <varname>$data</varname> argument is optional and used to
83 initialize the object value. If the <varname>$data</varname>
84 argument is omitted, the value is an empty string.
88 <sect3 id="zend.memory.memory-manager.objects-management.locked">
89 <title>Creating Locked Objects</title>
92 Create locked objects (objects, which are not swapped) using
93 the <methodname>Zend_Memory_Manager::createLocked([$data])</methodname> method:
96 <programlisting language="php"><![CDATA[
97 $memObject = $memoryManager->createLocked($data);
101 The <varname>$data</varname> argument is optional and used to
102 initialize the object value. If the <varname>$data</varname>
103 argument is omitted, the value is an empty string.
107 <sect3 id="zend.memory.memory-manager.objects-management.destruction">
108 <title>Destroying Objects</title>
111 Memory objects are automatically destroyed and removed from
112 memory when they go out of scope:
115 <programlisting language="php"><![CDATA[
118 global $memoryManager, $memList;
122 $memObject1 = $memoryManager->create($data1);
123 $memObject2 = $memoryManager->create($data2);
124 $memObject3 = $memoryManager->create($data3);
128 $memList[] = $memObject3;
132 unset($memObject2); // $memObject2 is destroyed here
135 // $memObject1 is destroyed here
136 // but $memObject3 object is still referenced by $memList
137 // and is not destroyed
142 This applies to both movable and locked objects.
147 <sect2 id="zend.memory.memory-manager.settings">
148 <title>Memory Manager Settings</title>
150 <sect3 id="zend.memory.memory-manager.settings.memory-limit">
151 <title>Memory Limit</title>
154 Memory limit is a number of bytes allowed to be used by loaded
159 If loading or creation of an object causes memory usage to
160 exceed of this limit, then the memory manager swaps some other
165 You can retrieve or set the memory limit setting using the
166 <methodname>getMemoryLimit()</methodname> and
167 <methodname>setMemoryLimit($newLimit)</methodname> methods:
170 <programlisting language="php"><![CDATA[
171 $oldLimit = $memoryManager->getMemoryLimit(); // Get memory limit in bytes
172 $memoryManager->setMemoryLimit($newLimit); // Set memory limit in bytes
176 A negative value for memory limit means 'no limit'.
180 The default value is two-thirds of the value of
181 '<code>memory_limit</code>' in php.ini or 'no limit' (-1)
182 if '<code>memory_limit</code>' is not set in php.ini.
186 <sect3 id="zend.memory.memory-manager.settings.min-size">
187 <title>MinSize</title>
190 MinSize is a minimal size of memory objects, which may be
191 swapped by memory manager. The memory manager does not swap
192 objects that are smaller than this value. This reduces the
193 number of swap/load operations.
197 You can retrieve or set the minimum size using the
198 <methodname>getMinSize()</methodname> and
199 <methodname>setMinSize($newSize)</methodname> methods:
202 <programlisting language="php"><![CDATA[
203 $oldMinSize = $memoryManager->getMinSize(); // Get MinSize in bytes
204 $memoryManager->setMinSize($newSize); // Set MinSize limit in bytes
208 The default minimum size value is 16KB (16384 bytes).