News for hackers. Stuff that matters.
Re:C99/C11 dynamic array that mimics C++'s std::vector by kr7 on Saturday January 07, 2017 @11:53AM (#13345050)
kzrdude is referring to the allocation of the Array struct on the heap. It should be something like this instead:

    Array array_create(size_t size, size_t sizeof_data) {
        Array result;
        result.size = size;
        result.capacity = size;
        if(size) {
            result.data = malloc(size * sizeof_data);
        } else {
            result.data = NULL;
        }
        return result;
    }
Re:C99/C11 dynamic array that mimics C++'s std::vector by oconnor663 on Saturday January 07, 2017 @05:33PM (#13347056)
I think kzrdude is actually referring to the void* pointers that the individual elements of the array live behind. Each of those requires an allocation to insert them, and an extra pointer traversal to read them. In C++ they would live side by side instead, as in regular C arrays. In C you'd need the struct to be redefined for each element type (maybe with another macro) if you wanted the same efficiency.
Re:C99/C11 dynamic array that mimics C++'s std::vector by kr7 on Sunday January 08, 2017 @12:51AM (#13348518)
I'm not seeing that?

In ARRAY_PUSH_BACK, it just inserts the element directly into the buffer, provided there is enough capacity. There is no separate allocation for an element.

You don't need to redefine the struct for each element type, since the macro casts 'data' (type void *) to whatever the array's type is.

Re:C99/C11 dynamic array that mimics C++'s std::vector by oconnor663 on Sunday January 08, 2017 @04:35PM (#13352159)
You're totally right, I don't know what I was reading >.<
Re:C99/C11 dynamic array that mimics C++'s std::vector by kzrdude on Sunday January 08, 2017 @08:13AM (#13349563)
Yes exactly.