[Interest] memory fragmentation?

K. Frank kfrank29.c at gmail.com
Thu Aug 23 04:29:20 CEST 2012


Hi Jason!

On Wed, Aug 22, 2012 at 9:17 PM, Jason H <scorp1us at yahoo.com> wrote:
> ...
> And I am sure others are wondering, just as I still kinda do, if all this is
> worth it. And my only answer to that, is MS did it for .NET, so there's got
> to be some good reason why they did it like that.

I'm certainly no expert on this, but if I understand what you're asking,
I would comment as follows:

Garbage collection and new / free / RAII / destructors are two very
different approaches to memory management.

I don't want to reanimate any latent GC vs. RAII religious wars, but I
will say that partisans on both sides point out the advantages of their
favored approach (and reasonable people on both sides also point
out the disadvantage of their favored approach) and I agree that each
approach does have its specific advantages.

In my view c# is ms's competitive response to java, and .net is their
associated competitive response the the jvm, if you will.  ms might
have picked GC over RAII because of its advantages, or they might
have picked it because GC was a big selling point of java, so GC in
c# / .net would naturally be part of their competitive response.  I'm
not saying that the various advantages of GC didn't figure into ms's
decision to go with GC, but I'm quite certain that GC being a big
selling point of java was an important, if not dominant consideration.

Now I'll leave it to the experts to debate whether GC or RAII is the
better general-purpose approach, but once you go with GC, I firmly
believe that you should go the extra mile and go with a compacting
GC, and deal with the issue of memory fragmentation.  That is (for
a general purpose system) I think the incremental cost of adding
compaction to the GC is well justified by its benefits.

So, in my view:

   compete with java  -->  GC
   GC  -->  compacting GC

(or, alternatively, general goodness of GC  -->  GC, etc.), so that's
my explanation for why ms did it like that.

One last comment:  GC and RAII address, in part, similar issues.
Also, they don't play that nicely together.  So I see no compelling
reason to add GC to c++ (others disagree), nor to add RAII to java.
ms wants .net to be catholic -- an admirable goal if they can pull
it off honestly -- so they support c++, and you get their GC / RAII
hybrid.

If ms wants to be catholic, I guess I'm agnostic:  Lot's of things work
for me -- GC, RAII, ms's GC / RAII hybrid.  I may have my preferences,
but they all get the job done.  Who knows?  If Qt didn't exist, maybe
we'd all be programming in .net / wpf (or java / swing), and liking it, and
getting the job done (and enjoying the benefits of compacting GC regarding
the memory fragmentation issue).

Anyway ...

Happy Hacking!


K. Frank



More information about the Interest mailing list