- 1、本文档共12页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
结构体内存对齐问题(Structure memory alignment problem)
结构体内存对齐问题(Structure memory alignment problem)
Structure memory alignment problem.Txt occasionally look back, otherwise, always in search of, and do not know what you lost. Men pay for lovers, women pay for relationships, men and women grab money for friends. Men love to see the woman with their eyes, the most vulnerable to beauty, women love to see the man, the most vulnerable to grief torture. When a structure type is defined in C, is its size equal to the sum of the size of each field (field)? How will the compiler place these fields in memory? What does the ANSI C require for the memory layout of the structure? And can we rely on the layout of our programs? These questions may be obscure to many friends, so this article tries to explore the secrets behind them.
First of all, at least one thing for sure, it is ANSI C to ensure the field structure in memory occurs with their declaration order increasing, and the first field is equal to the first address of the entire structure, examples of the first address. For example, there is such a structure:
Struct, vector{int, x, y, Z;} s;
Int, *p, *q, *r;
Struct vector *ps;
P = s.x;
Q = s.y;
R = s.z;
PS = s;
Assert (P Q);
Assert (P R);
Assert (Q R);
Assert ((int*) PS = = P);
The above assertion / fail
At this point, a friend might ask, does the standard specify adjacent fields to be adjacent to memory?. Well, Im sorry, ANSI C has no guarantee that your program should not rely on this assumption at any time. Does that mean that we can never sketch a clearer and more precise structure memory layout? Oh, of course not. But lets get away from this problem for a moment and focus on another important issue - memory alignment.
The computer system has many practical restrictions on the basic types of data stored in the memory location, they will require these data the first address value is a number k (usually it is 4 or 8 times), this is the so-called memory alignment, and this k is called alignment modulus of this data type (a
您可能关注的文档
- 第八章脑血管疾病(The eighth chapter cerebrovascular disease).doc
- 第八篇 结缔组织病和风湿病(Eighth connective tissue diseases and rheumatism).doc
- 第八节 川 崎 病(The eighth section Kawasaki disease).doc
- 第六例——原发性干燥综合征、肺部阴影(Sixth cases of primary Sjogren's syndrome and pulmonary shadow).doc
- 第八部分 现场急救(The eighth part, on-the-spot emergency treatment).doc
- 第六感(Sixth senses).doc
- 第六章 脂类代谢(The sixth chapter is lipid metabolism).doc
- 第六章 基因组dna的提取(The sixth chapter is the extraction of genomic DNA).doc
- 第六章 心血管系统疾病(The sixth chapter is cardiovascular disease).doc
- 第六章 微生物的代谢习题(The sixth chapter is microbial metabolic exercises).doc
最近下载
- 小学体育_队列队形教学设计学情分析教材分析课后反思.doc
- 中建项目商务策划汇报模板.pptx
- 公路中小跨径钢-混组合梁桥标准图集(制订)》技术方案报告.docx
- “设计思维与方法”教案.ppt
- 大职赛生涯闯关参考答案.docx VIP
- 2022《美宜佳公司营运资金管理存在的问题及对策研究》开题报告文献综述(含提纲)3200字.docx VIP
- 长垣市人民医院西学中培训班《方剂学》考试.pdf VIP
- 苏教版一年级科学上册4.1《自然物与人造物》(课件).pptx
- 电子商务招聘简章模板.pdf
- 统编版小学语文二年级上册第六单元 先辈伟人 大单元整体学历案教案 教学设计附作业设计(基于新课标教学评一致性).docx
文档评论(0)