[問題] 關於free()不同型態的指標
開發平台(Platform): Win10
編譯器:gcc in minGNU for windows + NotePad++
額外使用到的函數庫(Library Used): 無
問題(Question):
在練習資料結構的graph時,用到一個destroy_graph的函數,
功能是將整個graph所占用到的空間都free掉
但由於引入的dataPtr 是用void*,想請問若不管使用者丟進來的
dataPtr是指向什麼變數型態,直接在graph的副程式中free(dataPtr),
如此會造成memory leakage嗎?
編譯器又是如何去判定free(ptr) 中的這個ptr是指向什麼資料型態、
該free多少單位的memory呢?
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
http://codepad.org/FET3H7It
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.227.0.168
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1545449563.A.8A3.html
※ 編輯: Archer55b6 (36.227.0.168), 12/22/2018 11:36:44
※ 編輯: Archer55b6 (36.227.0.168), 12/22/2018 11:40:11
※ 編輯: Archer55b6 (36.227.0.168), 12/22/2018 11:42:33
※ 編輯: Archer55b6 (36.227.0.168), 12/22/2018 11:48:42
→
12/22 12:02,
7年前
, 1F
12/22 12:02, 1F
→
12/22 12:03,
7年前
, 2F
12/22 12:03, 2F
→
12/22 12:03,
7年前
, 3F
12/22 12:03, 3F
→
12/22 12:04,
7年前
, 4F
12/22 12:04, 4F
→
12/22 12:05,
7年前
, 5F
12/22 12:05, 5F
→
12/22 12:06,
7年前
, 6F
12/22 12:06, 6F
感謝cole大的解釋,之後再練習實作看看doug lee's acllocater!
※ 編輯: Archer55b6 (36.227.0.168), 12/22/2018 15:34:54
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章