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).


Reply via email to