I'm not sure I completely understand you. What I'd like to allow would be something like this:
Octstr *foo; Octstr *bar; if (condition (bar)) { foo = do_something_with (bar); /* foo points to a new Octstr, refcount = 1 */ } else { foo = octstr_get_ref (bar); /* foo becomes a new reference to the Octstr pointed to by bar; refcount = 2 */ } do_something_else (foo); octstr_destroy (foo); /* refcount gets decremented. if it reaches zero, the Octstr actually gets released */ Regards Jörg -----Original Message----- From: Aarno Syvänen To: Jörg Pommnitz Cc: '[EMAIL PROTECTED]' Sent: 12/12/01 11:09 AM Subject: Re: Ref-Counted octstr Hi List & Jörg Jörg Pommnitz wrote: > > Hi List, > there is a number of unneeded octstr_duplicate calls in the > tree. These calls could easily be replaced by a octstr_getref > that increments a refcounter inside the octstr. > A refcount > 1 would make the octstr immutable (e.g. calls that > modify the contents are forbidden). octstr_destroy would decrement > the refcounter. Reaching zero would actually destroy the entity. > > All these things seem rather easy and sensible. > > What do you think? I think just removing them would be better. But it would nice if there would be some debugging method to spot these calls. Is it possible to use refcounter following way: if duplicate is needed, do the deed if is not, just print a debugging statement Aarno