Re: [gtk-list] Gtk--: Tracking down clobbered pointers and mysterious crashes



robert_gasch@peoplesoft.com writes:
> I'm experiencing 2 mysterious crashes in my Gtk-- program
> which I can't figure out and which I'm guessing to be some
> kind of pointer gone astray. What I'm wondering is this:
> 
> 1) Does anybody have any suggestions for some (software)
> tools which might aid in discovering these obsucre bugs?

There's easy solution. Avoid pointers. :)

> 2) I typically allocate most my Gtk-- objects on the stack.

Yes, it is ok. Gtk-- objects are meant to be allocated from class
scope. (though, there's some minor issues with gtk-- currently -
signal proxies are taking 14 bytes too much space - and there's often
ALOT of them in normal widgets..) But it'll be fixed before 1.2 gtk--.

Allocating from stack is ok on situations when you'd allocate other
objects from stack too. Its quite common to have main() program like this:

   Gtk_Main m(&argc,&argv);
   Gtk_MyFoobar b;
   b.show();
   m.run();

But using function local scope (==stack) for gtk-- objects can be
quite bad, if you dont call m.run() inside the function...

> Is this considered OK or would dynamic allocation be
> better? I seem to remember that Gtk objects are very
> small themselves and dynamically allocate the memory
> they need (which would make stack allocation OK). Any
> tips from the Gtk-- gurus?

dynamic allocation in c++ is always a source of possible errors and
c++ does support scopes really nicely. Almost all c++ features are
geared towards not using dynamic mem. See where Multiple inheritance
becomes useful, or object composition, or even slicing! - They're all
there to support programming style that tries to avoid dynamic memory
allocation and tries to do things by combining those tiny objects to
larger units - and then do dynamic allocation only to those larger
blocks.

-- 
-- Tero Pulkkinen -- terop@modeemi.cs.tut.fi --



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