我正在使用可变大小的 C 结构,如下所示:
typedef struct {
int num_elems;
int elem1;
} mystruct;
// say I have 5 elements I would like to hold.
mystruct * ms = malloc(sizeof(mystruct) + (5-1) * sizeof(int));
ms->num_elems = 5;
// ... assign 5 elems and use struct
free(ms);
最后一个 free() 会释放所有 malloc 的内容,还是只释放 sizeof(mystruct)?