Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The thing that stops you from doing data-flow freely in C or assembly is ownership of memory.

In a GCed language, you can freely your parameters into a complex returned structure; without GC, you can't mix up ownerships without a separate accounting system.

Consider:

    struct some_struct *f(int x, char *y)
    {
        struct some_struct *result = malloc(sizeof *result);
        if (x < 0)
            result->value = "negative";
        else
            result->value = y;
        return result;
    }
If you're writing functional code, the return values of your routines will normally be a function of the parameters, which often means wholesale inclusion. Without GC, you need to do a lot more preemptive copying, and freeing the resulting data structures is much more painful.

Alternative accounting systems can be used, e.g. arena or marker based allocation (freeing everything allocated when control returns to earlier points on the stack), or something else more involved. But it's not free.



C++11 allows you to write natural "value-oriented" code without paying a copying cost. This is thanks to RVO (return value optimization) and move semantics.


You might have noticed that we were talking about C and assembly.


There is often a great deal of copy elision when passing things by value when the compiler can prove it the copying itself won't cause side effects.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: