1 / 14

איסוף אשפה (Garbage collection)

איסוף אשפה (Garbage collection). כותרת חילופית : ניהול זיכרון דינמי (Dynamic memory allocation) ספר בתחום :. Garbage Collection: Algorithms for automatic dynamic memory management, Richard Jones and Rafael Lins, Wiley, 1999. כמה זיכרון צורכת התוכנית הבאה ?. 3. 4. p. p. 11. 12. p. 1.

Download Presentation

איסוף אשפה (Garbage collection)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. איסוף אשפה (Garbage collection) כותרת חילופית: ניהול זיכרון דינמי (Dynamic memory allocation) ספר בתחום: Garbage Collection: Algorithms for automatic dynamic memory management, Richard Jones and Rafael Lins, Wiley, 1999. כמה זיכרון צורכת התוכנית הבאה ? 3 4 p p 11 12 p 1 2 malloc malloc 7 8 malloc … malloc 5 malloc malloc 6 malloc 13 malloc 14 p 9 malloc malloc malloc 10 malloc malloc malloc סיבוכיות מקום נוסף O(n) סיבוכיות מקום O(1)

  2. איסוף אשפה (Garbage collection) כותרת חילופית: ניהול זיכרון דינמי (Dynamic memory allocation) ספר בתחום: Garbage Collection: Algorithms for automatic dynamic memory management, Richard Jones and Rafael Lins, Wiley, 1999. כמה זיכרון צורכת התוכנית הבאה ? 3 4 p 11 12 q 1 2 7 8 q … free free 5 free free 6 13 14 free free 9 10 הבעיה: איך לשחרר צמתים שהמתכנת לא שחרר באמצעות פקודת free.

  3. איסוף אשפה Garbage collection משתנים נוצרו בזמן ריצהע"י malloc Heap בעיית איסוף אשפה משתנים של התכנית מחסנית frame v1 קלט: v2 v3 x y פלט: z לשחרר את את צמתי האשפה ee hh אשפה :צמתים שאין אליהם מסלול מאף משתנה תכנית

  4. איסוף אשפה Garbage collection בעיית איסוף אשפה משתנים בזמן ריצה נוצרו ע"י malloc משתני התכנית v1 קלט: v2 v3 x y פלט: z לשחרר את את צמתי האשפה ee hh ב- malloc הבא מוצאים אבר מ- AVAIL

  5. ספירה Reference counting פתרון 1 1 1 v1 2 2 v2 1 v3 x 1 1 y 2 z 2 ee hh 1 להוסיף לכל צומת V שדה count השומר את מספר המצביעים אליו

  6. אלגוריתם • עדכן את count של V • בכל פעם שמשנים מצביע 2. אם count של V שווה 0 שים את הצומת ב- AVAIL 1 1 v1 2 2 v2 0 1 v3 x 1 1 y 2 z 2 2 1 ee hh AVAIL 1

  7. בעיה 1 1 v1 2 2 1 v2 1 v3 x 1 1 y 2 z 2 1 ee אין גישה למעגל hh 1

  8. סימון Tracing collector פתרון 2 אלגוריתםDepth First Search (DFS) v1 v2 v3 x y z ee hh

  9. אלגוריתםDepth First Search (DFS) חסרון: אלגוריתם רקורסיבי v1 v2 v3 x y z ee hh סבוכיות מקום O(n) אלגוריתם רקורסיבי משתמש במחסנית

  10. אלגוריתםDFS ללא רקורסיה v1 v2 v3 x y z ee hh איך נדע אם המצביע מקורי? נוסיף משתנה color לכל מצביע נניח שתמיד יש מצביע לצומת הקודמת

  11. דחיסה Compaction קלט: פלט: a b c d e f g v1 v2 v3 x y z ee hh

  12. דחיסה Compaction פלט: a b c d e f g v1 v2 v3 x y z ee hh

  13. שימו לב n = 7 a b c d e f g v1 v2 v3 x y 1. לספור את מספר הצמתים z ee 2. לקצות מקום hh 3. לעביר ולהחליף בכתובת 4. עדכון מצביעים

  14. n = 7 a d b e f c g v1 v2 v3 x y 1. לספור את מספר הצמתים z ee 2. לקצות מקום hh סבוכיות מקום O(1) 3. לעביר ולהחליף בכתובת 4. עדכון מצביעים

More Related