Subj : Re: Performance Interfacing to C++ To : netscape.public.mozilla.jseng From : Thorsten R Date : Sat Aug 28 2004 03:04 am > You can use JSPROP_SHARED to avoid a value slot for such properties, but > the engine will still build a hash table per object map (per object with > its own properties, not one delegating all properties to its prototype), > and those hash table entries will point into a global (per-runtime) > lexicographic tree. Can you give me a hint how to create an object which delegates all properties to its prototype? Or is this the default as long as I don't add any individual properties to an object? I'm currently using JS_InitClass() to create my prototype and then JS_DefineObject() for each instance of my internal C++ objects. I do not add any additional properties or methods to individual instances. (BTW, I found out that using a prototype requires about half as much memory than calling JS_DefineObject() without a prototype.) > Strings require special handling even if you store references to them in > your private (to the JS engine) data and do not use value slots (i.e., > use JSPROP_SHARED as suggested above), if you want to avoid JS taking > ownership of the malloc'd jschar array, or copying from your storage > into its own. See JS_AddExternalStringFinalizer and its comments in > jsapi.h. Thank you for pointing me to this function. I think I have to call JS_NewExternalString() in my C++ getter to return an internal C++ string to the JS engine, is this correct? If my finalizer callback function is called, do I *need* to free the string? I don't think so. And I can't do so, because it is freed in the destructor of my C++ object. Is it possible to call JS_AddExternalStringFinalizer() with finalizer = NULL, so I just get my type-code? There comes one additional question to my mind: Let's assume I have a C++ class "Text" with a member char *m_szStr, which is "exported" to the JS engine as the property "Text.Str". Then I execute the following JS code: Text.Str = "Hello World"; Text.Str = "xyz"; If the C++ setter is called the second time by the engine due to the assignment (Text.Str = "xyz"), is it safe to free my internal C++ string at that moment? Or am I not allowed to do so, because the GC or anything else in SpiderMonkey is still working with it, and I must wait until my StringFinalizer callback is called? Regards Thorsten .