假设我有以下内容:
typedef struct a_struct_s
{
int* dynamic_pointer;
}
a_struct;
a_struct make_struct( int length )
{
a_struct s;
s.dynamic_pointer = calloc( sizeof( int ), length );
// [check here to see if s.dynamic_pointer was allocated]
return s;
}
既然make_struct()
会返回 struct 的副本,那么s
被它封装的指针会不会泄漏内存而无法释放?此外,副本本身与动态分配是否有性能成本s
?