Re: Gtk+ 3.0 and gtkmm-3.0



On Tue, 2008-04-08 at 14:53 +0200, Germán Diago wrote:
> 
> > I personally like that the RefPtr makes it very obvious when an
> object
> > is being shared. If the class does it itself then it's not obvious
> when
> > reading code like this
> 
> > Something something2 = something;
> > something2.set_foo() //Also changes foo in something.
> 
> It would be completely safe to do something like this:
> 
> Gtk::TextBuffer buffer;
> 
> Gtk::TextView v1(&buffer);
> Gtk::TextView v2(&buffer);
> 
> because this is normal c++ practice. The buffer is shared. If you want
> you have the option to allocate buffer in the heap you can do it, but
> you
> needn't to do it.

This is wrong, so very wrong.

SomeNameSpace::shared_ptr<SomeObject> buffer (new SomeObject());

SomeOtherObject o1 (buffer);
SomeOtherObject o2 (buffer);

*that* is "standard" C++ practice.

the example you gave has all kinds of pitfalls related to memory
management. either the buffer has global scope, which is generally a bad
idea, or it has object scope, in which case calling it shared is a bit
of a misnomer. alternatively, it actually a pointer and on the heap, in
which case anyone can call "delete buffer" at any time and cause a
crash.





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