Should operator overload methods be virtual?

dsimcha dsimcha at yahoo.com
Tue Dec 1 14:05:14 PST 2009


== Quote from Steven Schveighoffer (schveiguy at yahoo.com)'s article
> On Tue, 01 Dec 2009 16:28:14 -0500, dsimcha <dsimcha at yahoo.com> wrote:
> > == Quote from Steven Schveighoffer (schveiguy at yahoo.com)'s article
> >> If the compiler could somehow
> >> optimize out all instances of the template function to reduce bloat, I
> >> think that would make it a little less annoying.
> >
> > What is the sudden obsession with code bloat here lately?  Check out this
> > StackOverflow question that I posed a few weeks ago.  If anyone has a
> > decent
> > answer to it, I'd love to hear it.
> If I'm writing template code effectively as a "macro" meaning "call this
> virtual method", then there is no point in having template code whatsoever.
> If I'm forced to write it because the compiler only will call a template,
> then I would like for the compiler to optimize out its "mistake".  Then I
> have no problem with it, because the net effect on the binary performance
> and size should be zero.  Even if I have to annotate the function to force
> it, that is fine with me.
> Larger programs take more memory to run, and longer to load.  Not that my
> D programs need to squeeze every ounce of power out of the system, but I
> think nowadays there's too little emphasis on executable size optimization
> (or even memory consumption).
> an ancecdote on bloatage:  I once had a driver for XP for my wireless USB
> network adapter that put an icon on the task tray, consuming roughly 10MB
> of memory.  Yep, to put an icon on the task tray, it needed 10MB.  Just in
> case I ever wanted to click on that icon to set up my wireless network
> (which I would never do because once it's set up, I'm done).  As a bonus,
> every week or so, some kind of memory leak would trigger, and it would
> consume about 200MB of memory before my system started thrashing and I had
> to kill the icon.  I tried to disable it and use Windows to configure my
> wireless card, and then it used 10MB to put a *grayed out icon* in the
> tray (which would continue the bonus plan).  I finally had to hunt down
> the offending executable and rename it to prevent it from starting.  And
> guess what?  the wireless adapter worked flawlessly.  It's shit like this
> that pisses me off when people say "oh, bloat is a think of the past, you
> get soo much memory and cpu now adays, you don't even notice it."  All
> those little 10MB programs add up pretty quickly.
> -Steve

No, I agree.  Space efficiency does matter.  I've certainly jumped through some
serious hoops to make my code more space efficient when dealing with large
datasets.  The thing is that, at least in my experience, in any modern
non-embedded program large enough for space efficiency to matter, the space
requirements are dominated by data, not code.  Therefore, I use as many templates
as I feel like and don't worry about it, and when I think about space efficiency,
I think about representing my data efficiently.



More information about the Digitalmars-d mailing list