or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
2022q1 Homework1 (lab0)
contributed by <
kuihao
>實驗環境
輸出呢?
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →作業要求
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →queue.[ch]
和連帶的檔案,測試後用 Git 管理各項修改,要能滿足$ make test
自動評分系統的所有項目。queue.[ch]
需修改的項目:lab0-c
專案,比較你自己實作的 merge sort 和 Linux 核心程式碼之間效能落差qtest
提供新的命令shuffle
,允許藉由 Fisher–Yates shuffle 演算法,對佇列中所有節點進行洗牌 (shuffle) 操作qtest
提供新的命令web
,提供 web 伺服器功能,注意: web 伺服器運作過程中,qtest
仍可接受其他命令qtest
執行過程中的錯誤qtest
再於命令提示列輸入help
命令,會使 開啟 Address Sanitizer 觸發錯誤,應予以排除qtest
實作的記憶體錯誤,並透過 Massif 視覺化 "simulation" 過程中的記憶體使用量,需要設計對應的實驗開發過程
開發準備
v1.90
,執行方語法檢視目前版本:- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →由上述得知,Linux Kernel 的 linked-list 結構稱為 list_head,list_head 專職於指向其他非連續記憶體並且有另一個專有名詞稱作 head,其存放著 list_head 型別的位址,其功用是找到整條 linked-list。
graphviz playground (線上繪圖編輯器)
協助繪製可用於實作 Stacks (like liunx kernel api document descriped, "This is good for implementing stacks.")
可用於實作 Queues (like liunx kernel api document descriped, "This is useful for implementing queues.")
將一個環切成兩個環,並指派給新的 head (head_to)
程式碼第 15、16 行
程式碼第 18 至 21 行
先利用 container 的型別與 member 的名稱,得到 container 與 member 之間的 offset。
q_new
(程式碼修改紀錄)
git commit -a 時會被偵測出 memory leak 問題,原因 2022 年系統軟體系列課程討論區: commit 的時候出現 memory leak ,並學習使用 valgrind 動態檢測。
後來參考同學們的實作方式才發現我當初誤會 head 的意義,head 不必實作成 element_t,只需生成 list_head (*) 指標作為新生成的空 Queue。
q_free
code edition history
Indirect pointer 風格的實作方式,每次先判斷 next pointer 是否指向 q_head (\(l\)),若否,表示還有 node 可以 free,先將 indirect pointer 指向下一個 node 的 next pointer,並將前一顆 node 釋放掉;反之,將 q_head 釋放。
然而,此寫法再執行時會指向並釋放 Null Address,主要問題發生在第 7 至 9 行,凸顯出我這個寫法不適合使用 indirect pointer。第 7 行,indirect 先指向 head 的 next 指標的位址,但並非直接指向 next node 的位址,當第 9 行釋放 head 的記憶體位置,便會連帶 head 的 next 指標一起釋放,因此 indirect 就指向非法記憶體位址。並且另一個問題是通常 head 所指的位置一開始不應該被釋放掉,這會導致演算法設計上不易追蹤 queue 的所在位置。 後來仔細研讀 list.h 發現 list_for_each_entry_safe,可以預先存取下下顆 node 的位址,如此一來即使釋放掉下顆 node,也能將指標指向下下顆位址。
q_insert_head
q_insert_tail
q_remove_head
q_remove_tail
q_release_element
q_size
也許能透過修改 queue 節點的 struct,或另外準備一個儲存空間專門存放 queue 的節點數量,並於生成、新增、刪除時都順便修改該數值,q_size 函式就能改為直接讀取該儲存值以提升效能。
q_delete_mid
q_delete_dup
核心想法:設置一個回收桶存放暫存的副本,最後再一次清空回收桶。
q_swap
q_reverse
q_sort
參考 「你所不知道的 C 語言: linked list 和非連續記憶體」的 indirect pointer 版本 mergeTwoLists、Mergesort_list
如何運用原本用於普通非環狀 linked list 的 Merge sort?
環狀 list
從 tail 切開 (head->prev->next = NULL) 變成非環狀 linked list,套用 Mergesort_list(),排序完成後再將尾端上鏈並順時針將每個 node 的 prev pointer 重新上鏈關於 Linux 的其他收穫
gdb
協助產生或解釋C語言宣告: cdecl
剪貼簿套件: xclip
多顯示器套件 (Multi-monitor): xrandr
HackMD 常用鍵盤快捷鍵 (keymap)
Github SSH keys 及將本地端 remote's URL 從 https 變更為 SSH
git push
時出現以下警告:依 Switching remote URLs from HTTPS to SSH 之步驟可順利更改設定,並成功執行
git push
tags:
linux2022