santi mavropoul Δημοσ. 28 Μαΐου 2008 Δημοσ. 28 Μαΐου 2008 Γεια σας,με αυτόν τον κώδικα η λίστα ταξινομείται βάση διεύθυνσης > /*===========================================================================* * free_mem * *===========================================================================*/ PUBLIC void free_mem(base, clicks) phys_clicks base; /* base address of block to free */ phys_clicks clicks; /* number of clicks to free */ { /* Return a block of free memory to the hole list. The parameters tell where * the block starts in physical memory and how big it is. The block is added * to the hole list. If it is continuous with an existing hole on either end, * it is merged with the hole or holes. */ register struct hole *hp, *new_ptr, *prev_ptr; if (clicks == 0) return; if ( (new_ptr = free_slots) == NIL_HOLE) panic("Hole table full", NO_NUM); new_ptr->h_base = base; new_ptr->h_len = clicks; free_slots = new_ptr->h_next; hp = hole_head; /* If this block's address is numerically less than the lowest hole currently * available, or if no holes are currently available, put this hole on the * front of the hole list. */ if (hp == NIL_HOLE || base <= hp->h_base) { /* Block to be freed goes on front of the hole list. */ new_ptr->h_next = hp; hole_head = new_ptr; merge(new_ptr); return; } /* Block to be returned does not go on front of hole list. */ while (hp != NIL_HOLE && base > hp->h_base) { prev_ptr = hp; hp = hp->h_next; } /* We found where it goes. Insert block after 'prev_ptr'. */ new_ptr->h_next = prev_ptr->h_next; prev_ptr->h_next = new_ptr; merge(prev_ptr); /* sequence is 'prev_ptr', 'new_ptr', 'hp' */ } /*===========================================================================* * merge * *===========================================================================*/ PRIVATE void merge(hp) register struct hole *hp; /* ptr to hole to merge with its successors */ { /* Check for continuous holes and merge any found. Continuous holes can occur * when a block of memory is freed, and it happens to abut another hole on * either or both ends. The pointer 'hp' points to the first of a series of * three holes that can potentially all be merged together. */ register struct hole *next_ptr; /* If 'hp' points to the last hole, no merging is possible. If it does not, * try to absorb its successor into it and free the successor's table entry. */ if ( (next_ptr = hp->h_next) == NIL_HOLE) return; if (hp->h_base + hp->h_len == next_ptr->h_base) { hp->h_len += next_ptr->h_len; /* first one gets second one's mem */ del_slot(hp, next_ptr); } else { hp = next_ptr; } /* If 'hp' now points to the last hole, return; otherwise, try to absorb its * successor into it. */ if ( (next_ptr = hp->h_next) == NIL_HOLE) return; if (hp->h_base + hp->h_len == next_ptr->h_base) { hp->h_len += next_ptr->h_len; del_slot(hp, next_ptr); } } Αυτό που προσπάθησα παρακάτω είναι να αλλάξω τον τρόπο ταξινόμησης ώστε η λίστα να ταξινομείται με βάση το μέγεθος. Έχω τονίσει τις 2 προτάσεις που άλλαξα στην Merge και για τις οποίες δεν είμαι σίγουρος.Στην free_mem νομίζω έχω κάνει τις σωστές αλλαγές. Αν γνωρίζει κάποιος ας μου πει,ευχαριστώ. > /*===========================================================================* * free_mem * *===========================================================================*/ PUBLIC void free_mem(base, clicks) phys_clicks base; /* base address of block to free */ phys_clicks clicks; /* number of clicks to free */ { /* Return a block of free memory to the hole list. The parameters tell where * the block starts in physical memory and how big it is. The block is added * to the hole list. If it is continuous with an existing hole on either end, * it is merged with the hole or holes. */ register struct hole *hp, *new_ptr, *prev_ptr; if (clicks == 0) return; if ( (new_ptr = free_slots) == NIL_HOLE) panic("Hole table full", NO_NUM); new_ptr->h_base = base; new_ptr->h_len = clicks; free_slots = new_ptr->h_next; hp = hole_head; /* If this block's address is numerically less than the lowest hole currently * available, or if no holes are currently available, put this hole on the * front of the hole list. */ if (hp == NIL_HOLE || clicks <= hp->h_len) { /* Block to be freed goes on front of the hole list. */ new_ptr->h_next = hp; hole_head = new_ptr; merge(new_ptr); return; } /* Block to be returned does not go on front of hole list. */ while (hp != NIL_HOLE && clicks > hp->h_len) { prev_ptr = hp; hp = hp->h_next; } /* We found where it goes. Insert block after 'prev_ptr'. */ new_ptr->h_next = prev_ptr->h_next; prev_ptr->h_next = new_ptr; merge(prev_ptr); /* sequence is 'prev_ptr', 'new_ptr', 'hp' */ } /*===========================================================================* * merge * *===========================================================================*/ PRIVATE void merge(hp) register struct hole *hp; /* ptr to hole to merge with its successors */ { /* Check for continuous holes and merge any found. Continuous holes can occur * when a block of memory is freed, and it happens to abut another hole on * either or both ends. The pointer 'hp' points to the first of a series of * three holes that can potentially all be merged together. */ register struct hole *next_ptr; /* If 'hp' points to the last hole, no merging is possible. If it does not, * try to absorb its successor into it and free the successor's table entry. */ if ( (next_ptr = hp->h_next) == NIL_HOLE) return; [size=2][b]if (hp->h_base + hp->h_len == next_ptr->h_len) [/b][/size] { hp->h_len += next_ptr->h_len; /* first one gets second one's mem */ del_slot(hp, next_ptr); } else { hp = next_ptr; } /* If 'hp' now points to the last hole, return; otherwise, try to absorb its * successor into it. */ if ( (next_ptr = hp->h_next) == NIL_HOLE) return; [size=2][b]if (hp->h_base + hp->h_len == next_ptr->h_len)[/b][/size] { hp->h_len += next_ptr->h_len; del_slot(hp, next_ptr); } }
narbi Δημοσ. 29 Μαΐου 2008 Δημοσ. 29 Μαΐου 2008 Το δοκίμασες? Έκανες boot το minix με αυτο τον κώδικα? Δούλεψε? Γενικά η λογική σου νομίζω πως είναι σωστή.. Κι εγώ έτσι σκέφτηκα...Τώρα ίσως να χρειάζονται και κάποιες παραπάνω αντικαταστάστεις. Δοκίμασε το όμως πρώτα...
santi mavropoul Δημοσ. 29 Μαΐου 2008 Μέλος Δημοσ. 29 Μαΐου 2008 narbi βασικά προσπαθώ μέσω της εντολής vi όνομα_αρχείου.txt να το τσεκάρω μα ενώ έχω γράψει τον παραπάνω κώδικα,το Minix με μπερδεύει κάπως σχετικά με την εκτέλεση.Αν γνωρίζεις την διαδικασία help me please. ΥΓ. Νομίζω πως ο κώδικας σε γενικές γραμμές είναι σωστός
narbi Δημοσ. 30 Μαΐου 2008 Δημοσ. 30 Μαΐου 2008 Κάνεiς save το αρχείο με τον vi και κάνεις πάλι compile. Πρέπει να έχεις κάνει compile και την πρώτη φορά πριν κάνεις τις αλλαγές.Σίγουρα, είναι και στο e-class οι οδηγίες..
santi mavropoul Δημοσ. 1 Ιουνίου 2008 Μέλος Δημοσ. 1 Ιουνίου 2008 narbi,ξέρω πως το στυλ γενικά των site με κώδικα κτλ είναι να μην δίνουν έτοιμες λύσεις (και δικαιολογημένα βέβαια) μα προσπαθώ πόσες μέρες τώρα την συνάρτηση Merge και καταλήγω στον παραπάνω κώδικα.Επειδή είναι η τελευταία μέρα και είναι και η τελευταία άσκηση και πρέπει να την έχω σωστή για να το περάσω αν μπορείς βοήθησε λίγο ως προς τις αλλαγές που έκανες στην Merge,την έχω πειράξει μα δεν είναι σίγουρος.(Τα υπόλοιπα όλα που άλλαξα στην free_mem νομίζω είναι σωστά) Δεν είμαι σίγουρη και πολύ έμπειρη,αν γνωρίζει και μπορεί κάποιος,ας βοηθήσει,ευχαριστώ.
narbi Δημοσ. 1 Ιουνίου 2008 Δημοσ. 1 Ιουνίου 2008 Λοιπόν, άκου τι να κάνεις για να τσεκάρεις τον κώδικά σου.. Θα ανοίξεις το minix204.Αφού μπεις με το = κωδικός root κτλ. θα πατήσεις : cd .. cd usr/src make world Αυτό θα κάνει την πρώτη μετάφραση του Minix (πριν κάνεις τις αλλαγές όπως το κατέβασες!!) και θα πάρει λίγη έως αρκετή ώρα.Στη συνέχεια θα μπείς στο alloc.c και θα κάνεις τις μετατροπές σου και ύστερα για να χρησιμοποιήσεις τον καινούριο πυρήνα πηγαίνεις στον φάκελο tools που βρίσκεται μέσα στον /usr/src και πληκτρολογείς: make hdboot Αυτή νομίζω πως είναι η διαδικασία..Αν κάνω λάθος ας με διορθώσει κάποιος..
santi mavropoul Δημοσ. 2 Ιουνίου 2008 Μέλος Δημοσ. 2 Ιουνίου 2008 ok narbi,βασικά αν πρόσεξες η Merge με ενδιαφέρει μόνο,τα άλλα όλα με πολλά πειράματα,ψάξιμο και αλλαγές τα βρήκα.anw, αφού δεν την κατάφερα,διότι θέλει κι άλλες αλλαγές από αυτές που φαίνονται αρχικά,μάλλον την επόμενη φορά Ευχαριστώ
narbi Δημοσ. 2 Ιουνίου 2008 Δημοσ. 2 Ιουνίου 2008 Σάντη εγώ νομίζω ότι ο κώδικάς σου σε γενικές γραμμές είναι καλός έστω και με αυτές τις αλλαγές μόνο. ίσως να μην πάρεις και 10 αλλά θα πάρεις κατα πάσα πιθανότητα έναν βαθμό που θα σε βοηθήσει να περάσεις το εργαστήριο. Σημασία έχει που ασχολήθηκες κι έμαθες. Εύχομαι κάθε επιτυχία στην εξέτασή σου. ΥΓ. Αυτό που δεν καταλαβαίνω είναι η εμμονή σου να προσπαθείς να αποφύγεις το compile όταν αυτό είναι το κλειδί για να διορθώσεις και να τελειοποιησεις έναν κώδικα..
santi mavropoul Δημοσ. 2 Ιουνίου 2008 Μέλος Δημοσ. 2 Ιουνίου 2008 Δυστυχώς,δεν πήγα καθόλου καλά.Narbi,compile κάνω,να δω το πρόγραμμά μου να τρέχει και να κάνει αυτά που του έχω πει,αυτό δεν μπόρεσα να κάνω.
narbi Δημοσ. 2 Ιουνίου 2008 Δημοσ. 2 Ιουνίου 2008 Δυστυχώς,δεν πήγα καθόλου καλά.Narbi,compile κάνω,να δω το πρόγραμμά μου να τρέχει και να κάνει αυτά που του έχω πει,αυτό δεν μπόρεσα να κάνω. Σαντυ δεν βλέπεις κανένα πρόγραμμα να τρέχει...Επαληθευεται ο κώδικάς σου αν μετά το compile τρέχει πάλι το ΜΙΝΙΧ και εκτελεί σωστά τις εντολές.
santi mavropoul Δημοσ. 2 Ιουνίου 2008 Μέλος Δημοσ. 2 Ιουνίου 2008 Ε μα έλα που το Minix bootαρε και έτρεχε μια χαρά
narbi Δημοσ. 3 Ιουνίου 2008 Δημοσ. 3 Ιουνίου 2008 Ε μα έλα που το Minix bootαρε και έτρεχε μια χαρά Τότε δεν καταλαβαίνω που είχες πρόβλημα...Από τη στιγμή που έτρεχε ενώ είχες αλλάξει τον κώδικα... Don't worry.
santi mavropoul Δημοσ. 3 Ιουνίου 2008 Μέλος Δημοσ. 3 Ιουνίου 2008 Εγώ δεν είχα κανένα,η καθηγήτρια είχε μεγάλο πρόβλημα,με το σκεπτικό που ακολούθησα στην Merge.Την άλλη φορά θα το περάσω..
Προτεινόμενες αναρτήσεις
Αρχειοθετημένο
Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.