2024-10-08/15 課程問答簡記
檢討和回顧
學員作業清單
櫻木滑倒-Sakuragi
linked list
華一跤-slipontheway
P76131351 :
- 「從 linked list 中取出一個節點」的應用場景?以任務管理、排程為例如何包裝?
- 從 task list 中挑出任務並移走 。將問題包裝為在一個ready queue中選擇要執行的task,將其標為執行中並從ready queue中移除。
參考 :快慢指標
2024-10-15
devarajabc
- 如何將 in-order 的表示式新增至 binary-tree
8+9x5 => 8, 2^16 +1 ,9, 2^16+2, 5
使用 RPN(逆波蘭表示法)
過程發生的問題
- 對觀念不夠熟悉,在 Approach 階段沒有將 RPN 與面試題目對應。
- 在提出 Approach 階段沒有將程式碼列出。Approach 階段可以列出部分程式碼。
- 程式與提出的 Approach 看不出有二元樹與 RPN 的跡象。至少要有關鍵程式碼
jychen0611
(good) memory allocator
- de-fragmentation
- fast vs. O(1)
- first-fit
- Maximizing throughput
- minimizing the average time to satisfy allocate and free requests
- Maximizing memory utilization
- 可被分配的記憶體空間受限於 disk 中 swap space 的大小
- peak utilization
- 表完成第 k 個請求後,總分配出去的 payload 大小
- 表當前 heap 大小 (單調非遞減)
https://ossna2017.sched.com/event/BCsR
process control block (PCB)
ready queue
https://wiki.csie.ncku.edu.tw/embedded/freertos
- Explicit allocator
- 須由 programmer 主動呼叫 free 釋放空間
- C, C++
- Implicit allocator (garbage collector)
- allocator 自動偵測未被 program 使用的 block,並釋放該 block
- Lisp, ML, and Java
Implementation Issues
- Free block organization.
- How do we keep track of free blocks?
- Placement.
- How do we choose an appropriate free block in which to place anewly allocated block?
- Splitting.
- After we place a newly allocated block in some free block, what do we do with the remainder of the free block?
- Coalescing.
- What do we do with a block that has just been freed?
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
如圖,參考 CS:APP 的作法,
block = a one-word header + payload + some additional padding
考慮 32-bit 系統, 2-word(=2*4byte) alignment 的情境,每個 block 的大小必為 8 bytes 的倍數,因此末三 bits 必為 0,可用來存放其他資訊。
- header 的前 29 bits 用以表示空間大小,剩餘 3 bits 用以表達該空間是否 free。
- 此外,malloc 回傳位址應為 payload 起始位置,由於 header 大小為 1-word,需移動 4 bytes,相當於 4 個 char。
- free 時由於輸入為 payload 起始位置,若要修改 header 資訊則需走 4 bytes 回來,才能指向 header。
P76131589
infix(中序表示式) 轉換成 postfix(後序表示式): Shunting Yard Algo.