by halayli · 10y ago · 0 comments
x = malloc(sizeof x + <variable_length))
x->zero_array points to the variable_length.
The advantage is that you get contiguous memory access and do a single malloc.
As opposed to:
x = malloc(sizeof
x)x->ptr = malloc(<variable_length>);
x and ptr are not necessarily contiguous.
See [0] for a picture.
x = malloc(sizeof(x) + <variable_length>);
x->ptr = x + sizeof(x);