动态分配一个对象,结构中不是ptrs(不是动态分配)的成员会在堆栈而不是堆中吗?

Dynamically allocate an object, will the members that aren't ptrs (not dynamically allocated) in the struct be in the stack instead of the heap?

假设我有这个结构:

typedef struct List_object list;
struct List_object {
    char* name;
    struct stat stats;
};

主线:

list** listObjects = malloc(sizeof(list*) * n);
    for(int i = 0; i < n; i++) {
        listObjects[i] = malloc(sizeof(list));
        listObjects[i]->name = malloc(sizeof(char) * 124);
    }

然后我有一个设置它们的函数:

void setListObjects(char* name, struct stat stats);

我想知道数组 listObjects 的每个对象中的数据成员 struct stat stats 是否也会在堆中?

或者它只会是 listObjects 及其数据成员 name 因为它们都是用 malloc[=29 分配的=],而不是 stats?

I was wondering if the data member struct stat stats in each object of the array listObjects will be in the heap as well?

是的。每个结构成员都将分配在堆上。尽管请注意,虽然您示例中的指针 name 本身将与堆上的结构一起分配,但它指向的内容可以是任何东西。