[英]Paging and non-contiguous memory allocation
我對 x86_64 Linux 操作系統中的 memory 管理幾乎沒有疑問。
如果我從我的用戶空間代碼中分配一個 2000 字節的數組(靜態 - arr[2000];
或動態 - malloc(2000);
),這些將是物理 memory 中的連續 memory 嗎?
If I allocate memory (same above example, statically - arr[2000];
or dynamically - malloc(2000);
) will there be a page table updation to map to these 2000 bytes
in physical memory, so that the future references to these memory地址可以從頁表條目中找到嗎?
1) 不太可能。 “你的” malloc() 可能會產生結果,但你不能依賴它。
你想要做的是 malloc(4000) 然后有兩個指針。 一個指向 malloc,另一個指向指針 1+2000。
請注意,當您釋放(指針1)時,您也會使指針2無效。
2) 直到您引用該區域內的一個字節。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.