Stanford CS107 Lecture 23:把 realloc 留在原地,必須守住哪些 allocator 不變量
CS107 第 23 講把 explicit free list 推進到原地 realloc:縮小時切出可用區塊,放大時吞併右側 free blocks,做不到才配置、複製、釋放;每一步都要同時維持實體 heap 與邏輯 free list。
CS107 第 23 講把 explicit free list 推進到原地 realloc:縮小時切出可用區塊,放大時吞併右側 free blocks,做不到才配置、複製、釋放;每一步都要同時維持實體 heap 與邏輯 free list。
CS107 第 11 講先收完 calloc、strdup、free、realloc 的 heap 契約,再把 swap 從多份型別專用程式改造成 void * 加 byte count:C 的泛型不是保留未知型別,而是明確交接位址、寬度與解讀責任。
CS107 第 21 講從 allocator 的 alignment、throughput 與 utilization 目標出發,以 bump allocator 和 implicit free list 拆解 metadata、splitting、placement、內部與外部碎片,以及 free 後為何必須 coalesce。
CS107 第 22 講把 implicit free list 改成 explicit free list:搜尋只拜訪可重用 blocks,但每塊 free memory 同時具有實體相鄰順序與邏輯鏈結順序,unlink、coalesce、reinsert 必須共同維持不變量。
CS107 第 20 講把 reverse engineering 能力放回倫理脈絡:privacy 有個人與社會模型,trust 等於 reliance 加上 betrayal risk;接著複習 process memory,從 malloc client 轉成 heap allocator implementer。
CS107 第 10 講從 sizeof 與 pointer arithmetic 走進 stack frame lifetime:回傳 local array 會留下 dangling pointer;malloc 讓資料跨越函式返回,但也把 NULL、容量計算、ownership、free 與 memory leak 交給程式設計者。