看板 C_and_CPP 關於我們 聯絡資訊
補充說明(Supplement): " 經典編程 900 例" 應是對岸的書, 內容推測應和版上常見 FAQ 蠻相似的。 不知是否有人看過? 好奇的是裡面到底是用哪一套 complier ? 網路上查,有些人是分類在 "VC 分享" 裡面 不過看裡面的例子.. #include <io.h> #include <fcntl.h> #include <sys\stat.h> #include <dirent.h> #include <dos.h> fcntl.h, stat.h , direct.h , 這些都不像是 vc 有的 是早期 tc 嗎?還是其它 Linux 下 complier ? // ============= 分隔線 ================== 為了確定這本書的品質,我想抓一段我覺得有點怪的 code 問一下 // ============= 分隔線 ================== int c[3][10] = {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, {21, 22, 23, 24, 25, 26, 27, 28, 29, 30}}; long sum_array(int array[], int elements) { long sum = 0; int i; for (i = 0; i < elements; i++) sum += array[i]; return(sum); } printf("Sum of third array elements %d\n", sum_array(c, 30)); // ============= 分隔線 ================== 我看樣子是覺得很奇怪啦, 我知道即使是二維陣列也是連續記憶體, 但若維度一調大,記憶體有可能發生碎片化的情形嗎? 是聽過 "記憶體碎片化" 的問題, 這不會發生在靜態陣列上嗎? ( 爬文 search "碎片", 目前版上似乎沒人討論這問題..) 最後感謝各位指教, 感激不盡! -- YouLoveMe() ? LetItBe() : LetMeFree(); -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 180.177.76.142 ※ 編輯: tropical72 來自: 180.177.76.142 (12/16 04:43) ※ 編輯: tropical72 來自: 180.177.76.142 (12/16 04:47)
ericinttu:作業系統裡面的fragment 12/16 07:11
ericinttu:我沒測試過這現象,但腦內模擬器推斷應該會有機會因為可 12/16 07:16
ericinttu:用記憶空間是分散的情況下,而使得無法再配置出一塊大的 12/16 07:16
ericinttu:空間給新的變數用. 12/16 07:17
tropical72:謝謝您的回覆,好奇的是上述碼於碎片化仍可正常運作? 12/16 07:51
tropical72:只是運作速度較慢而已嗎? 12/16 07:51
chchwy:現在OS都有paging的機制啦 目的之一就是徹底解決碎片化 12/16 11:09
chchwy:程式看見的都是virtual address 12/16 11:10
chchwy:要經過page table映射才會變成physical address 12/16 11:10
chchwy:physical再怎麼碎 virtual addr看起來連續就好 12/16 11:11
tropical72:感謝說明 !! 12/16 18:29
ericinttu:感謝強者說明 12/17 03:19