Getting completely (I mean ENTIRELY) rid off GC

po via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 12 01:50:15 PDT 2014


> programmers who really have this stuff down... how much of your 
> code and your mental energy with C++ is spent on memory 
> ownership rules?  Is it really a productive use of your time?  
> Does the program materially benefit from the design required to 
> make it safe, correct, and self-documenting with respect to 
> memory ownership and data lifetime?  Are smart pointers really 
> that pleasant to work with?

  It just depends on the codebase.

  Yes old C++ codebases are terrible for multithreaded code. It 
would be nightmare to make sense of it and guarantee it doesn't 
have bugs.

  But using modern C++11/14 + TBB it really isn't hard at all. It 
is fairly trivial to scale to N cores using a task based 
approach. Smart pointers are rarely used, most C++ stuff is done 
by value.
   When dynamic lifetimes are required, again it is rarely based 
on "shared_ptr", far more often it is "unique_ptr" so there is no 
atomic ref counting that the GC crowd loves to cry about.
  C++ also has all kinds of parallel loop constructs(via TBB,  
OpenMP, or MS Concurrency RT  etc). Again trivial to use.
   TBB has many parallel containers(priority queue, vector, 
unordered_map).


  For instance, I work on a game engine, almost everything is 
either by value or unique.

The only stuff that is "shared" and thus is requires ref counting 
are external assets(shaders,models,sounds, some gpu resources). 
These objects are also closed, and thus incapable of circular 
references. Their ref counts are also rarely modified, at most 
I'd expect just a few of them to dec/inc per frame as objects are 
added/removed.







More information about the Digitalmars-d mailing list