[PHP-DEV] Weak references in PHP

2003-02-28 Thread Konstantin Knizhnik
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



Re: [PHP-DEV] Weak references in PHP

2003-02-28 Thread George Schlossnagle
Can anybody tell me if such features are available in PHP (I failed to 
find
them myself).
Look at __destruct method for classes in ZE2.  They wopn't tell you the 
reference count, but the do get called when the ref count goes to 0.

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


Re: [PHP-DEV] Weak references in PHP

2003-02-28 Thread Andi Gutmans
Hi,

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

Andi

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


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


Re[2]: [PHP-DEV] Weak references in PHP

2003-02-28 Thread Konstantin Knizhnik
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,
 Konstantinmailto:[EMAIL PROTECTED]


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



Re[2]: [PHP-DEV] Weak references in PHP

2003-02-28 Thread Konstantin Knizhnik
Hello George,

Friday, February 28, 2003, 5:46:18 PM, you wrote:

 Can anybody tell me if such features are available in PHP (I failed to 
 find
 them myself).

GS Look at __destruct method for classes in ZE2.  They wopn't tell you the 
GS reference count, but the do get called when the ref count goes to 0.


Sorry, I am dummy in PHP world:( Can you explain more precisely what
is ZE2 and where should I look for __destruct method.
I didn't find any reference to such method neither in PHP manual
neither in PHP sources i have downloaded.

-- 
Best regards,
 Konstantinmailto:[EMAIL PROTECTED]


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



Re: Re[2]: [PHP-DEV] Weak references in PHP

2003-02-28 Thread George Schlossnagle
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.
It's in ZE2  have a look at Zend/ZEND_CHANGES in the source tree for 
details (you'll need to be running php5/HEAD).  And it's a userland 
method, so the cache can be implemented in PHP.

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


Re: Re[2]: [PHP-DEV] Weak references in PHP

2003-02-28 Thread J Smith

ZE2 == Zend Engine 2, which will be replacing the current Zend Engine in PHP
5. Amoung other things, one of it's main features is a more roboust OOP
framework, which includes class destructors.

J


Konstantin Knizhnik wrote:

 Hello George,
 
 Friday, February 28, 2003, 5:46:18 PM, you wrote:
 
 Can anybody tell me if such features are available in PHP (I failed to
 find
 them myself).
 
 GS Look at __destruct method for classes in ZE2.  They wopn't tell you
 the GS reference count, but the do get called when the ref count goes to
 0.
 
 
 Sorry, I am dummy in PHP world:( Can you explain more precisely what
 is ZE2 and where should I look for __destruct method.
 I didn't find any reference to such method neither in PHP manual
 neither in PHP sources i have downloaded.
 


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



Re[2]: [PHP-DEV] Weak references in PHP

2003-02-28 Thread Andi Gutmans
At 08:00 PM 2/28/2003 +0300, Konstantin Knizhnik wrote:
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.
If you need to go over a list of million objects you are doing something 
wrong :)


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.
I disagree. JDO performs well and doesn't cache the objects as usually 
pessimistic locking is used with it. Of course, if you want to use 
optimistic locking and the nature of your application allows you to do so 
efficiently the caching might make sense (or it's mainly a read-only app).


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.
I don't quite understand why you need __destruct() as other systems in Java 
don't use this but I might be completely misunderstanding what you want to do.
Yes, you'll need to do this with a C extension.
Anyway, good luck. I hope the Engine 2 solves some of your problems (such 
as object handles which allow you to always access the same DB object).
Andi

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