内存对齐,malloc内存对齐
来源:互联网 发布:不锈钢锅有毒吗 知乎 编辑:程序博客网 时间:2024/06/01 10:21
1 #include <iostream>
2 #include <cstdlib>
3 using namespace std;
4
5 int main()
6 {
7 struct {
8 int a;
9 long b;
10 float c;
11 double d;
12 }var;
13 int a[5] = {0};
14 cout << "a address:" << (int*)a << endl;
15 cout << a << endl;
16 cout << "int: " << sizeof(int) << endl;
17 cout << "long: " << sizeof(long) << endl;
18 cout << "float: " << sizeof(float) << endl;
19 cout << "double:" << sizeof(double) << endl;
20
21 cout << &(var.a) << endl;
22 cout << &(var.b) << endl;
23 cout << &(var.c) << endl;
24 cout << &(var.d) << endl;
25 int *pa = (int*)malloc(sizeof(int));
26 long *pb = (long*)malloc(sizeof(long));
27 float *pc = (float*)malloc(sizeof(float));
28 double *pd = (double*)malloc(sizeof(double));
29 cout << pa << endl;
30 cout << pb << endl;
31 cout << pc << endl;
32 cout << pd << endl;
33
34 delete pa;
35 delete pb;
36 delete pc;
37 delete pd;
2 #include <cstdlib>
3 using namespace std;
4
5 int main()
6 {
7 struct {
8 int a;
9 long b;
10 float c;
11 double d;
12 }var;
13 int a[5] = {0};
14 cout << "a address:" << (int*)a << endl;
15 cout << a << endl;
16 cout << "int: " << sizeof(int) << endl;
17 cout << "long: " << sizeof(long) << endl;
18 cout << "float: " << sizeof(float) << endl;
19 cout << "double:" << sizeof(double) << endl;
20
21 cout << &(var.a) << endl;
22 cout << &(var.b) << endl;
23 cout << &(var.c) << endl;
24 cout << &(var.d) << endl;
25 int *pa = (int*)malloc(sizeof(int));
26 long *pb = (long*)malloc(sizeof(long));
27 float *pc = (float*)malloc(sizeof(float));
28 double *pd = (double*)malloc(sizeof(double));
29 cout << pa << endl;
30 cout << pb << endl;
31 cout << pc << endl;
32 cout << pd << endl;
33
34 delete pa;
35 delete pb;
36 delete pc;
37 delete pd;
38 }
0 0
- 内存对齐,malloc内存对齐
- 关于glibc的malloc内存对齐
- 关于glibc的malloc内存对齐
- malloc内存分配字节对齐问题
- 内存对齐的malloc、realloc、free
- 关键字 对齐 内存对齐
- 内存对齐
- 内存对齐
- 内存对齐
- 内存对齐
- 内存对齐
- 内存对齐
- 内存对齐
- 内存对齐
- 内存对齐
- 内存对齐
- 内存对齐
- 内存对齐
- input type=file
- 设计模式读书笔记(三) Builder(建造者)模式
- 基础算法之插入排序
- Java常用类库——国际化程序(Locale,ResourceBundle以及MessageFormat处理动态文本)
- IOS中单例怎么销毁,会造成内存泄露吗?
- 内存对齐,malloc内存对齐
- 在Eclipse中安装Zookeeper状态查看插件
- 什么是动态数据类型
- viewpager的简单实现
- Qt学习十一:Qt+VS练习一:Qt的UI布局和在VS中的配合
- ViewPage+Fragment 懒加载+只加载一次 SwipeRefreshLayout自动刷新
- 设计模式总览
- 使用BitmapShader实现简单绘图
- React Native 开发到上线记录(二)