POV-Ray : Newsgroups : povray.off-topic : Learning C# : Re: Learning C# Server Time
29 Jul 2024 04:30:36 EDT (-0400)
  Re: Learning C#  
From: Warp
Date: 29 Sep 2012 15:44:38
Message: <50674fa6@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> Well, C++'s target platforms include things that C# isn't targeted at. If 
> you're trying to fit your code into a credit card terminal, you're going to 
> be worried about C++ template code bloat and the features of C#'s execution 
> model won't even enter the conversation.

"Template code bloat" is a myth with little to no actual evidence.

If you need the same code to handle more than one type, you have to do that
somehow. Either you duplicate the code for each type, or you use runtime
polymorphism, or alternatively you use some really contrived code full of
conditionals that checks the actual type of the data when it tries to use it.

In most cases option #1 is most probably going to take *less* memory and
be a lot more efficient than either of the other options. That's because
with option #1 the compiler can optimize the code for those types while
with the other options it can't. In fact, your code might become *smaller*
when it's optimized for each type rather than larger.

Even if it doesn't become smaller, the increase in memory usage will most
probably be less than with the other solutions. If even that's too much,
then you shouldn't be using several types in the first place, but than it's
not the templates' fault, it's your own fault for wanting to use several
types on a machine with 1 kilobyte of RAM.

> The reason C++ makes more code is that it actually does stuff like inline 
> the right calls, doing type-specific generic expansions.

Inlining can actually *reduce* the size of the binary in some cases (because
of the subsequent compile-time optimizations).

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.