确实结构与单个构件具有相同的性能作为一个部件类型? [英] Does struct with a single member have the same performance as a member type?
本文介绍了确实结构与单个构件具有相同的性能作为一个部件类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
确实结构
与单个成员具有相同的性能成为会员类型(内存使用和速度)?
Does struct
with a single member have the same performance as a member type (memory usage and speed)?
示例
这code是结构
有一个成员:
This code is a struct
with a single member:
struct my_int
{
int value;
};
时的表现 my_int
相同 INT
?
推荐答案
同意@harper整体,但要注意以下几点:
Agree with @harper overall, but watch out for the following:
一个经典的差异被认为是与结构的非结构化阵列和阵列。
A classic difference is seen with a "unstructured" array and an array in a structure.
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);
这篇关于确实结构与单个构件具有相同的性能作为一个部件类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文