On Tue, Nov 15, 2011 at 12:35 PM, Yang Guo <[email protected]> wrote:
> I had the impression that the data method in the resource may return
> different pointers, as long as the string content is the same. But in
> the case Vitaly described, it would indeed be easier and better to
> just cache the string pointer. How/when are external strings disposed?
> Would it be possible to replace the resource field by the string
> pointer after the first call of resource()->data(), destruct the
> resource object since we dont need it anymore, and change the map to
> indicate this?

The data() method indeed may return different pointers (provided the
string content is the same), but it has no way to detect when a
previously returned pointer is no longer required so it has to keep it
valid. That said, I don't think right now V8 really exercises on this
property, most accesses are short lived.

So, yes, it's tempting to replace the resource pointer with the data
pointer right away, but the embedder relies on the destructor of the
resource object being called when the string is GC'ed to clean up the
native state. Search for "ExternalStringTable".


-- Vitaly

> On Nov 15, 2011, at 20:12, "[email protected]" <[email protected]> wrote:
>
>> My immediate thought would be the same: If we have a word to spare in the 
>> String
>> structure, we might as well let it point directly to the real character data
>> instead of pointing to an intermediate buffer.
>> It might require tweaking of GC, since it would be a native pointer, but so 
>> is
>> the resource pointer, so it should be doable.
>>
>> We were considering adding such a pointer recently, but the overhead of 
>> adding
>> an extra pointer to all external strings seemed steep. It's a good idea to 
>> only
>> do it to some strings.
>>
>>
>>
>> http://codereview.chromium.org/8568013/
>

-- 
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to