具有单个成员的 struct
是否具有与成员类型相同的性能(内存使用和速度)?
示例:
这段代码是一个只有一个成员的struct
:
struct my_int
{
int value;
};
my_int
的性能和int
一样吗?
最佳答案
同意@harper总体而言,但要注意以下几点:
“非结构化”数组和结构化数组之间存在典型差异。
char s1[1000];
// vs
typedef struct {
char s2[1000];
} s_T;
s_T s3;
调用函数时...
void f1(char s[1000]);
void f2(s_T s);
void f3(s_T *s);
// Significant performance difference is not expected.
// In both, only an address is passed.
f1(s1);
f1(s3.s2);
// Significant performance difference is expected.
// In the second case, a copy of the entire structure is passed.
// This style of parameter passing is usually frowned upon.
f1(s1);
f2(s3);
// Significant performance difference is not expected.
// In both, only an address is passed.
f1(s1);
f3(&s3);
关于c - 具有单个成员的结构是否具有与成员类型相同的性能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19877792/