Monday, November 08, 2010

int 在 Stack 所占的空間

Test Code :
// VarWidth.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include
using namespace std;

int AddFunc(int x, int y) {
int a = 0, b = 0, c = 0;

cout << "x addr : " << &x << endl;
cout << "y addr : " << &y << endl;

cout << "a addr : " << &a << endl;
cout << "b addr : " << &b << endl;
cout << "c addr : " << &c << endl;

__asm{
mov eax, dword ptr[esp+4]
mov ebx, dword ptr[esp+8]
add eax, ebx
}
return 0;
}

int main(int argc, char* argv[])
{
int iRet = 0;
int x = 1, y = 2;
iRet = AddFunc(x, y);
// printf("Hello World!\n");
return 0;
}


Default 情況下 :









若是直接用 esp + offset Access Variable 的話, V$.net Debug Version 會用掉 12 Bytes, 如果 Debug / Release 都只要 4 Bytes 的話可以 follow 這一篇 : http://www.eggheadcafe.com/software/aspnet/29178215/an-int-that-is-4-bytes-in-native-and-12-bytes-in-net-huh.aspx

我負責

 ... + ...........  政策 我負責. 負責推卸責任. (阿不然你以為哩...) 聽說 記錯了 請見諒 深感抱歉.... 抗(國外)疫(苗)中...