Wprowadzenie do Zend Framework

     Nauka Zend Framework


     Przewodnik po Zend Framework

  • Zend_Gdata
  • Zend_Http
  • Zend_InfoCard
  • Zend_Json
  • Zend_Layout
  • Zend_Ldap
  • Zend_Loader
  • Zend_Locale
  • Zend_Log
  • Zend_Mail
  • Zend_Markup
  • Zend_Measure
  • Zend_Memory
  • Zend_Mime
  • Zend_Navigation
  • Zend_Oauth
  • Zend_OpenId
  • Zend_Paginator
  • Zend_Pdf
  • Zend_ProgressBar
  • Zend_Queue
  • Zend_Reflection
  • Zend_Registry
  • Zend_Rest

  • Zend_Search_Lucene
  • Zend_Serializer
  • Zend_Server
  • Zend_Service
  • Zend_Session
  • Zend_Soap
  • Zend_Tag
  • Zend_Test
  • Zend_Text
  • Zend_TimeSync
  • Zend_Tool
  • Zend_Tool_Framework
  • Zend_Tool_Project
  • Zend_Translate
  • Zend_Uri
  • Zend_Validate
  • Zend_Version
  • Zend_View
  • Zend_Wildfire
  • Zend_XmlRpc
  • ZendX_Console_Process_Unix
  • ZendX_JQuery
  • Translation 21.3% Update 2011-11-16 - Revision 24356 - Version ZF 1.11.x

    46.3. Memory Objects

    46.3.1. Movable

    Create movable memory objects using the create([$data]) method of the memory manager:

    $memObject $memoryManager->create($data);

    "Movable" means that such objects may be swapped and unloaded from memory and then loaded when application code accesses the object.

    46.3.2. Locked

    Create locked memory objects using the createLocked([$data]) method of the memory manager:

    $memObject $memoryManager->createLocked($data);

    "Locked" means that such objects are never swapped and unloaded from memory.

    Locked objects provides the same interface as movable objects (Zend_Memory_Container_Interface). So locked object can be used in any place instead of movable objects.

    It's useful if an application or developer can decide, that some objects should never be swapped, based on performance considerations.

    Access to locked objects is faster, because the memory manager doesn't need to track changes for these objects.

    The locked objects class (Zend_Memory_Container_Locked) guarantees virtually the same performance as working with a string variable. The overhead is a single dereference to get the class property.

    46.3.3. Memory container 'value' property

    Use the memory container (movable or locked) 'value' property to operate with memory object data:

    $memObject $memoryManager->create($data);


    $memObject->value $newValue;

    $memObject->value[$index] = '_';


    $memObject->value substr($memObject->value$start$length);

    An alternative way to access memory object data is to use the getRef() method. This method must be used for PHP versions before 5.2. It also may have to be used in some other cases for performance reasons.

    46.3.4. Memory container interface

    Memory container provides the following methods: getRef() method

    public function &getRef();

    The getRef() method returns reference to the object value.

    Movable objects are loaded from the cache at this moment if the object is not already in memory. If the object is loaded from the cache, this might cause swapping of other objects if the memory limit would be exceeded by having all the managed objects in memory.

    The getRef() method must be used to access memory object data for PHP versions before 5.2.

    Tracking changes to data needs additional resources. The getRef() method returns reference to string, which is changed directly by user application. So, it's a good idea to use the getRef() method for value data processing:

    $memObject $memoryManager->create($data);

    $value = &$memObject->getRef();

    for (
    $count 0$count strlen($value); $count++) {
    $char $value[$count];
    } touch() method

    public function touch();

    The touch() method should be used in common with getRef(). It signals that object value has been changed:

    $memObject $memoryManager->create($data);

    $value = &$memObject->getRef();

    for (
    $count 0$count strlen($value); $count++) {
        if (
    $condition) {
    $value[$count] = $char;

    $memObject->touch(); lock() method

    public function lock();

    The lock() methods locks object in memory. It should be used to prevent swapping of some objects you choose. Normally, this is not necessary, because the memory manager uses an intelligent algorithm to choose candidates for swapping. But if you exactly know, that at this part of code some objects should not be swapped, you may lock them.

    Locking objects in memory also guarantees that reference returned by the getRef() method is valid until you unlock the object:

    $memObject1 $memoryManager->create($data1);
    $memObject2 $memoryManager->create($data2);


    $value1 = &$memObject1->getRef();
    $value2 = &$memObject2->getRef();

    for (
    $count 0$count strlen($value2); $count++) {
    $value1 .= $value2[$count];

    $memObject2->unlock(); unlock() method

    public function unlock();

    unlock() method unlocks object when it's no longer necessary to be locked. See the example above. isLocked() method

    public function isLocked();

    The isLocked() method can be used to check if object is locked. It returns TRUE if the object is locked, or FALSE if it is not locked. This is always TRUE for "locked" objects, and may be either TRUE or FALSE for "movable" objects.

    digg delicious meneame google twitter technorati facebook