Re: Garbage Collection - The Trash Begins To Pile Up
Dave Harris wrote:
I don't know what doing that would mean. Words like "match" and "perfect"
are too weasely.
So I guess, in my case, since I share the same philosophy, I would be
Weasely Wabbit. :)
GC helps with memory management. It doesn't help with destructors. The
issues are more or less orthogonal. Traditionally C++ has combined them so
that destructors do memory management, and GC separates them again.
Separating them helps because many objects don't actually have non-memory
resources to free and these objects become simpler to manage.
I am trying to understand what you mean here. Are you saying, in
general coding, this:
is less desirable than this:
Window *pwind = new Window();
And further, the objects which do need resources generally do so for
external reasons. (I want to say "domain reasons", but that's not quite
right.) This is because the resources are, almost by definition,
externally visible. And so the external reasons will also tell you when
the resource should be freed. It's almost at the level of, "When the user
clicks the OK button, the dialog disappears" telling you which event
should be responsible for freeing the dialog's window handle.
I noticed that you have used GUI as an example. It is widely known in
the GUI programming community that the design of the window handling
system, in Windows (and I believe X too), positively resists RAII. And
there is little you can do about it, and as I recall, many programmers
who go to create "nice wrapper frameworks" around the window handle
lament rather than laud this fact.
You may still be left with cases where the answer is not spelt out for
you. These may be hard cases in themselves, but the fact that 99% of the
cases have been dealt with easily, should give you the time to think
through the hard ones. Which, after all, is what you are being paid for.
So, I will ask a question that I would like to ask all the heaphiliacs
Dear Heapaphiliacs and Stackphiliacs:
As you go about your day-to-day programming, which style of programming
do you use. Style 1 or Style 2 (see above)?
And now for a different question:
Which style of programming do you think ultimately results in better
form, maintainability, robustness, etc. Style 1 above or Style 2? In
other words, if you were teaching a bunch of engineers how to program
at a top technical university, which style would you recommend to your
students if they asked? Please do not respond with, "It depends on the
situation, yada..".I already know that. What I am asking is, in
practice, which situation arises more often, and with what frequency? I
would like a rough breakdown of percentages if you can provide them.
Stack-Based Allocation: 50%
Heap-Based Allocation: 50%
-Le Chaud Lapin-
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]