Adding Java and C++ to the MQTT benchmarks or: How I Learned to Stop Worrying and Love the Garbage Collector

Ola Fosheim Grøstad" <ola.fosheim.grostad+dlang at gmail.com> Ola Fosheim Grøstad" <ola.fosheim.grostad+dlang at gmail.com>
Thu Jan 9 00:40:29 PST 2014


On Thursday, 9 January 2014 at 07:07:29 UTC, Walter Bright wrote:
> and it works without copying in D, it just returns s1. In C, I 
> gotta copy, ALWAYS.

Only if you write libraries, in an application you can set your 
own policies (invariants).

> (C's strings being 0 terminated also forces much extra copying, 
> but that's another topic.)

Not if you have your own allocator and split chopped strings (you 
can just overwrite the boundary character).

> The point is, no matter how slow the GC is relative to malloc, 
> not allocating is faster than allocating, and a GC can greatly 
> reduce the amount of alloc/copy going on.

But since malloc/free is tedious c-programmers tend to avoid it 
by embedding objects in large structs and put a variable sized 
object at the end of it... Or have their own pool (possibly on 
the stack at the location where it should be released).




More information about the Digitalmars-d mailing list