Hello Andi,

The problem is that script can fetch very large number of objects
and all of them doesn't fit in the memory. Lets say we have very
large list of objects (several millions objects or more). And our
script traverse the list and fetch objects one by one and do some
calculations (for example calculates total sum). So at each moment of
time only one persistent object is actually needed. But without weak
references we will have to keep all these millions of objects in
memory.

Also performance of OODBBS greatly depends on efficient
caching of objects. If we throw away all objects after each request
and has to reload them from the server for each request, then
performance will we awful. It is very significant to be able to cache
most frequently used objects. LRU or some other discipline can be
used for it. But any not depending from the discipline we use we need
some  mechanism which allows to map OPIDs to instances and do not
prevent GC from collecting the objects.

That is why almost all languages with implicit memory
deallocation have some kind of weak references. And I was wondered
when do not find such facility in PHP.

Using __destruct method (thanks to George) it may be possible to implement
what I need, but only if object cache is implemented in C (and so is
not visible for PHP garbage collector). So no pure PHP solution exits.
Unfortunately I didn't fins any reference to __destruct method in PHP
manual and do not understand how it works. If I just declare
__destruct method in class, it is not invoked when object is
destructed.



Friday, February 28, 2003, 6:29:21 PM, you wrote:

AG> Hi,

AG> I don't quite understand. If you are thinking of implementing something 
AG> similar to JDO then your persistent object manager will only hold the 
AG> objects which are retrieve by the script. At the end of the request it'll 
AG> persist the changes and will free the objects. Why would you want them to 
AG> be destroyed during the request?

AG> Andi

AG> At 02:39 PM 2/28/2003 +0300, Konstantin Knizhnik wrote:
>>To be able to implmenet interface of object-oriented database to PHP I need
>>to
>>have object cache which will map persistent object identifier (OPID) to
>>loaded instance of the object. This cache should be "weak", i.e. it should
>>not prevent garbage collection from deallocating unused instances of
>>peristent object (otherwise all database will be soon loaded in memory)..
>>
>>As far as I understand, PHP uses GC bases on refernce couters. Also I do not
>>find something like weak reference in language manual. There are two other
>>ways how to solve the problem
>>without weak references:
>>1. Be able to check valye of reference counter (so I can check the it is
>>equal to 1 and if so remove this object from object cache)
>>2. Be able to detect the moment when object is removed by GC (in this case I
>>can make object cache invisible for GC and when object is deleted, it will
>>be also unlinked frmo object cache).
>>
>>Can anybody tell me if such features are available in PHP (I failed to find
>>them myself).
>>Or may be there is some other way to solve the problem?
>>
>>Thanks in advance
>>Konstantin
>>
>>
>>
>>--
>>PHP Development Mailing List <http://www.php.net/>
>>To unsubscribe, visit: http://www.php.net/unsub.php



-- 
Best regards,
 Konstantin                            mailto:[EMAIL PROTECTED]


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to