Re: When and when not to use Glib::RefPtr?

On Monday 11 April 2005 01:53, Murray Cumming wrote:


> In general we avoid guessing such (undocumented) internal lifetime
> details, and just do the same thing with all GObjects. C coders do
> whatever works, with lots of errors along the way.

Typically, in a case such as this, where the holding of a reference counting 
smart pointer is not enough to ensure the usable lifetime of the object, C++ 
would use a weak pointer.

You are being unkind to C coders. Although glibmm does not provide weak 
pointers, C coders have glib, which does: it provides 
g_object_add_weak_pointer() ("Adds a weak reference from weak_pointer to 
object to indicate that the pointer located at weak_pointer_location is only 
valid during the lifetime of object. When the object is finalized, 
weak_pointer will be set to NULL"), together with 
g_object_remove_weak_pointer(), g_object_weak_ref() and 
g_object_weak_unref(), and GWeakNotify(), for the purpose.

The glib weak pointer will tell the user precisely whether the object it 
references is valid or not.


Summer is y-cumen in, lhude sing, cuccu!
Groweth sed and bloweth med, springeth the wude nu.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]