[erlang-questions] Erlang and Akka

Thu Aug 28 15:20:43 CEST 2014

> On Thu, Aug 28, 2014 at 1:58 PM, Richard A. O'Keefe <ok@REDACTED>
> wrote:
>> Memory management is the programmer's job in C++, which
>> means that any realistic C++ program *has* to use mutable
>> variables or run out of memory in seconds.
> Sure, so can we maintain acyclic data structures (as in Erlang, as I
> understand) with smart pointers in order to eliminate most *manual* memory
> management and to write in such a style as coding in Erlang?

(a) Smart pointers *are* manual memory management.
    You have to remember to use them all the time,
    because if you forget and use the language's native
    pointers, you're sunk.  There are several kinds to
    choose from, and you have to understand the consequences.
    Using the wrong kind of xxxx_ptr can be disastrous.

(b) Smart pointers are not just manual memory management,
    they are a particular *style* of memory management.
    A style that makes *using* a smart pointer quite expensive.
    In fact, there is space bloat as well: 'smart pointers'
    really point to 'control blocks' which contain built-in
    pointers to object (amongst other fields).

(c) C++11 smart pointers are sort of thread safe and sort of
    not.  Threads can safely manipulate *different* smart pointers
    to the same *controi block*.  If you're dealing with immutable
    objects the fact that this doesn't make access to the
    pointed-to object safe won't matter; the fact that concurrent
    access to the smart pointer itself may.

> In general maybe using value types, i.e. stack-allocated wrappers for
> heap-allocated memory (e.g. smart pointers), can help in such coding
> style?

C++ never saw a problem it couldn't solve with a few extra
templates and some time/space bloat.  This is _not_ the way
C++ "wants" to be used, and if you try to write Erlang in
C++, C++ will punish you by making conceptually simple things
look fiendishly complicated.  Nor in that case are you likely
to get the performance C++ is celebrated for.

More information about the erlang-questions mailing list