RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
c#如何探索内存大小段存储

这篇文章将为大家详细讲解有关c#如何探索内存大小段存储,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

创新互联建站于2013年开始,先为梧州等服务建站,梧州等地企业,进行企业商务咨询服务。为梧州企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

1.c#如何探索内存大小段存储

A的ASCII码16进制存储为41,对应B,C,D,E为42,43,44,45;

VS下为小段模式

2.c#如何探索内存大小段存储

将高精度存入低精度时,截取掉高位,高位补ff,内存中默认用cc初始化

c#如何探索内存大小段存储

3.

#include
#pragma pack(4)
struct A
{
	int a;
	char b;
	short c;
	char d[11];
};
aaaab0cc
dddddddd
ddd//应补齐最大对齐数的整数倍
int main()
{
	
	cout << sizeof(A) << endl;
	cout << offsetof(A,a) << offsetof(A,b) << offsetof(A,c) << offsetof(A,d) << endl;
	system("pause");
	return 0;
}

运行结果为:20   0,4,6,8

4.

struct B
{
int a;
char c;
double d;
};
//aaaac000
//dddddddd
cout << sizeof(B) << endl;
cout << offsetof(B,a) << offsetof(B,c) << offsetof(B,d) << endl;

运行结果:16  0,4,8

5.

struct A
{
	int a;
	char b;
	short c;
	char d[11];
};
struct B
{
	int a;
	char c;
	double d;
	A e;
};
cout << sizeof(B) << endl;
cout << offsetof(B, a) << offsetof(B, c) << offsetof(B, d) << offsetof(B, e) << endl;

运行结果:36  0,4,8,16

e不是对齐到d后面,按A本身最大整数倍对齐数。

6.

#include
#pragma pack(4)
struct A
{
	int a;
	char b;
	short c;
	char d[11];
};
struct B
{
	int a;
	double d;
	char c;
	A e;
};
cout << sizeof(B) << endl;
cout << offsetof(B, a) << offsetof(B, c) << offsetof(B, d) << offsetof(B, e) << endl;

运行结果:36   0,4,12,16

7.

#include
#pragma pack(8)
struct A
{
	int a;
	char b;
	short c;
	char d[11];
};
struct B
{
	int a;
	double d;
	char c;
	A e;
};
cout << sizeof(B) << endl;
cout << offsetof(B, a) << offsetof(B, c) << offsetof(B, d) << offsetof(B, e) << endl;

运行结果:40   0,8,16,20

关于“c#如何探索内存大小段存储”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。


分享题目:c#如何探索内存大小段存储
文章URL:http://scyingshan.cn/article/psophs.html