《C++ Footprint and Performance Optimization》读书笔记

P75

 

 1 // hmjtestasm.cpp : 定义控制台应用程序的入口点。
 2 //
 3 
 4 #include "stdafx.h"
 5 #include "stdio.h"
 6 long MulOperator(void);
 7 int DoWop(int dow,int op);
 8 
 9 struct A{char a;long b;char c;long d;};
10 #pragma pack(push,1)
11 struct B{char a;long b;char c;long d;};
12 #pragma pack(pop)
13 int _tmain(int argc, _TCHAR* argv[])
14 {
15     char vara;
16     int varb;
17     varb=DoWop(1,2);//result : varb=3
18     printf("varb is :%d\n",varb);
19     printf("%d is \n",MulOperator());//turn to shift
20 
21     printf("size of struct a : %d\n",sizeof(A));//16
22     printf("size of struct b :%d\n",sizeof(B));//10
23     vara=getchar();
24     return 0;
25 }
26 
27 long MulOperator(void) 28 { 29 long i,j=1031; 30 for (i=0;i<20000000;i++) 31 { 32 j*=2; 33 //j*=3;//生成的汇编代码不同 34 } 35 return j; 36 } 37 inline int DoWop(int dow,int op) 38 {//在微软开发平台内联汇编 39 __asm 40 { 41 mov eax,dow; 42 add eax,op; 43 } 44 }

 

 书中源码下载:http://is.gd/cppfootprint

本书出版社地址:http://www.informit.com/store/c-plus-plus-footprint-and-performance-optimization-9780672319044

posted on 2013-06-06 14:34  zhiying678  阅读(271)  评论(0编辑  收藏  举报

导航