POV-Ray : Newsgroups : povray.off-topic : Coding in the mainstream : Re: Coding in the mainstream Server Time
29 Jul 2024 04:30:11 EDT (-0400)
  Re: Coding in the mainstream  
From: Warp
Date: 7 Jun 2012 09:23:39
Message: <4fd0ab5b@news.povray.org>
Invisible <voi### [at] devnull> wrote:
> >> ...or rather, to /use/ run-time polymorphism, you need to do manual
> >> memory management, and manual memory management is infamously hard.
> >
> > ... or use Boost's (or C++11's) smart pointers.

> Wouldn't that mean I'd have to somehow install Boost and tell the IDE 
> where the hell to find it?

> Compared to that, manual memory management sounds trivial. :-P

  Just use a compiler that support C++11. You can then use std::shared_ptr
to manage the objects. (If the object doesn't need to be shared, only moved
around, then you can use std::unique_ptr instead, which is more efficient.)

  To be fair, though, if your program allocates and deallocates such objects
in large quantities very fast, the Java version will probably be faster than
the C++ version (because memory allocation has been optimized in Java but
not in C++).

  (To be clear: It's not the polymorphism that's slow in C++. It's all the
new's and delete's.)

  Some applications require runtime polymorphism of objects (GUI programming
being the most prominent example), but in many cases compile-time
polymorphism using templates is enough (and significantly more efficient).

-- 
                                                          - Warp


Post a reply to this message

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