RE: [PHP-DEV] Re: [DICUSS]Cleanup resource handling APIs
| From: | François Laupretre | Date: | Wed, 04 Feb 2015 06:25:12 +0000 |
| Subject: | RE: [PHP-DEV] Re: [DICUSS]Cleanup resource handling APIs | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-81766@lists.php.net to get a copy of this message | ||
> De : Xinchen Hui [mailto:laruence@php.net]
> > I don't understand how you can delete the resource if you remove the
> handle from the zend_resource struct. Or would you store the index
> elsewhere ?
>
> if you use HashTable , yes, it's hard to get rid of it, but we can
> hidden it from user land..
>
> and actually, we only use integer index of regular_list for zend_resource..
>
> if we decide to remove handle, then it maybe easy to re-implement it
> as a plain c array like zend_resource[];
>
> and when doing realloce, we allocate new segment, and link them togther.
Anyway, IMO, moving resources from HashTable to a plain C array is a good thing. Allocating segments
of 20 structs, for instance, would be fine as a single segment would fit 99.9 % of the cases. This
way, you could even compute a pseudo resource handle from the zend_resource address (for
var_dump()). The only additional thing you would need is a field to mark the resource as
deleted/invalid. But setting ptr to NULL and type to -1 would be probably enough.
I am interested in the subject of resources because I just implemented a resource abstraction layer
in php-ext-gen (https://github.com/flaupretre/php-ext-gen). The objective being to use the same user
code for PHP 5 and 7. Maybe you can have a look at the project and give me your opinion.
Regards
François