LinkedIn Article to be: Why you need to start moving off C/C++ to D, now.

Tobias Müller via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 17 23:42:53 PDT 2014


"deadalnix" <deadalnix at gmail.com> wrote:
> On Thursday, 17 July 2014 at 19:58:32 UTC, Tobias Müller wrote:
>> IMO manual memory management is quite easy. In 99% of all cases > ownership
>> is clear to trivial.
>> 
>> But maybe this is just because I usually write C++ and > ownership is crucial
>> in C++. Maybe it's more difficult if your accustomed to a GC.
>> 
>> Tobi
> 
> Except that you and I both do a shitton of stupid mistakes when
> coding all the time. And if you think you don't, you probably do
> a lot more than I (as being blind to one's own weakness usually
> don't help improving).

I'm well aware of that, otherwise I wouldn't be reading here (and on rust
mailing list).

I don't want to advertise completely manual memory management, don't get me
wrong. But most of the time GC and RC are just overkill because ownership
is clear.

> As a result, even when hat needs to be done is obvious (which it
> is quite often when it come to memory allocations) mistake will
> creep in.

My point was not that errors cannot happen but more that as you say it "hat
needs to be done is obvious" in most cases.

> Memory allocation mistake are special. They lead to memory leak
> (which won't show up in tests,

With deterministic memory management they do. Just scan the heap before and
after the tests (or a bunch of tests).

> but only after tue program is long
> running, which lead to long and annoying debuging experience
> where you try to analyze the heap and find how the hell you ended
> up allocating all of this)

In my experience memory leaks are seldom a problem. They are easily
detected, found and fixed.

More difficult to find are "false" memory leaks, memory that is not needed
but still referenced. But those also happen with automatic memory
management.

> or worse, undefined behavior (which
> typically will cause crashes in unrelated part of the code,
> leading to even more confusing debuging sessions).

Memory corruption is a different beast, those bugs are really hard.

But (again IME) memory management is most often not the cause of those.
Multithreading issues are much more prominent.

> As such, automatic memory management has value in itself. It is a safe default.

That's for sure. But GC/RC are overkill in most cases. Static verification
of ownership is often enough.

> I understand that manual memory management is often
> needed, and that is why we need way to escape that and manually
> manage.

And with a little bit of care/encapsulation also quite safe.

But again, I don't want to advertise manual memory management, but I just
don't agree with the premise that ownership relations are so complex that
deallocation becomes unpredictable.

Tobi


More information about the Digitalmars-d mailing list