Hacker News new | past | comments | ask | show | jobs | submit login

Mayhaps because the structure was originally stack-allocated, or because the developer was unfamiliar or uncomfortable with intrusive datastructures. Or because the structure is used outside of linked list contexts and the memory overhead of the intrusion was considered not compensated for?



> Or because the structure is used outside of linked list contexts

That use case is possible with the particular implementation that is now used by curl:

    struct fileinfo {
      struct curl_fileinfo info;
      struct curl_llist_element list;
    };
You can use the payload (struct curl_fileinfo) outside of a list without incurring any overhead.

I think one of your other points is more likely, or simply "it was fast enough and we went for more interesting features than for such optimizations".


One of the Plan 9 C enhancements makes this even easier by permitting the fields of these structs to be accessed directly.


you can do this now in ISO C11 with the inclusion of anaonomous structures and unions.

    struct A { 
        int x, y; 
    };

    struct B {
        union {
            struct A 2d;
            struct { int x, y; };
        }
        int z;
    };

    ...

    struct B foo;
    foo.x = foo.2d.y = foo.z = 0;
you can access x and y as members of B or A.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: