考慮以下**:
c# code
unsafe
,size is ,value is
", (
uint
)pb,
sizeof
(byte
), b);
console.writeline(
"address of d is 0x,size is ,value is
", (
uint
)pd,
sizeof
(double
), d);
console.writeline(
"address of i is 0x,size is ,value is
", (
uint
)pi,
sizeof
(int
), i);
console.writeline(
"address of pb is 0x,size is ,value is 0x
", (
uint)&
pb,
sizeof
(byte
*), (
uint
)pb);
console.writeline(
"address of pd is 0x,size is ,value is 0x
", (
uint)&
pd,
sizeof
(double
*), (
uint
)pd);
console.writeline(
"address of pi is 0x,size is ,value is 0x
", (
uint)&
pi,
sizeof
(int
*), (
uint
)pi);
}
在我機子上顯示的輸出結果是
address of b is 0x12f46c,size is 1,value is 3
address of d is 0x12f464,size is 8,value is 10
address of i is 0x12f460,size is 4,value is 5
address of pb is 0x12f45c,size is 4,value is 0x12f46c
address of pd is 0x12f458,size is 4,value is 0x12f464
address of pi is 0x12f454,size is 4,value is 0x12f460
現在我的問題是:看**,堆疊應該是從高位址向低位址向下填充,byte只佔1個位元組,而32位處理器系統堆疊的記憶體塊總是按照4位元組的倍數進行分配的。b的位址是0x12f46c,那麼b這個值應該儲存在0x12f468~0x12f46b中,佔4個位元組,然後為d分配記憶體,double型別佔8個個位元組,其位址應該是0x12f468,d應該儲存在0x12f460~0x12f467中,但為什麼輸出結果b佔了8個位元組的記憶體而d卻只佔了4個位元組的記憶體呢。
另外如果把**的最後三行去掉,即變成
c# code
unsafe
,size is ,value is
", (
uint
)pb,
sizeof
(byte
), b);
console.writeline(
"address of d is 0x,size is ,value is
", (
uint
)pd,
sizeof
(double
), d);
console.writeline(
"address of i is 0x,size is ,value is
", (
uint
)pi,
sizeof
(int
), i);
}
輸出結果為
address of b is 0x12f45c,size is 1,value is 3
address of d is 0x12f460,size is 8,value is 10
address of i is 0x12f468,size is 4,value is 5
記憶體分配變成了從低位址到高位址向上填充,但此時b佔了4個位元組,d佔了8個位元組,何解?
未解決問題備份
1.對於重複類的問題依然不太明確 記得當時上課的時候說過一些,但是不太記得了,是否是這樣?如下 當我們有兩個不同的jar包 test 1.0.jar test 2.0.jar,而這兩個jar包定義了相同的全限定類,並且兩個jar同時存在與classpath時,jvm在使用哪個jar包的同名類上是不確...
Vue中問題總結 與未解決問題總結
問題一 error in render typeerror cannot read property matched of undefined 使用路由之後報錯,路由書寫錯誤,下面是我寫的錯誤的路由 這是修改之後正確的 router才是vue例項化的配置欄位名稱,寫個其他的它當然不認識了。真是低階錯...
遞迴解決問題(c語言)
前面我們知道了什麼是遞迴以及遞迴是怎麼實現的,現在我們就用遞迴來解決一些小問題,本文題目來自pat浙大版 c語言程式設計 第3版 題目集 本題要求實現乙個計算非負整數階乘的簡單函式,並利用該函式求 1 2 3 n 的值。函式介面定義 double fact int n double factsum ...