To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 3541
3540  |  3542
Subject: 
Re: My problems with adding a Best Fit algorithm for memory management to kernel/mm.c
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Sat, 6 Dec 2003 18:29:39 GMT
Viewed: 
3927 times
  
In lugnet.robotics.rcx.legos, Michael Obenland wrote:
Michael Martelli wrote:
Nevermind, I figured out the error after I posted and reviewed my code again.

Fine. Could you please post the solution? I don't like unsolved riddles :)

Regards,

Michael

Sure thing sorry, the problem was that I had the wrong variable in one of the if
statement, I copied it over wrong from my hand-written notes I made of the Alg

=================================================
void *malloc(size_t size)
{
      size_t *ptr,*next, bestSize, *mm_best_free;

      size=(size+1)>>1;

   #ifdef CONF_TM
   ENTER_KERNEL_CRITICAL_SECTION();
   #endif

      ptr=mm_first_free;
      mm_best_free=ptr;
bestSize=0xFFFF;

mm_best_free++; //this must point to the size portion of the header

      while(ptr>=mm_first_free) //&mm_start gives the same results
      {
         if(*(ptr++)==MM_FREE)
         {
         #ifdef CONF_TM
         mm_try_join(ptr);
         #endif

            if(*ptr>=size)
            {
               if(bestSize>(*ptr)) //THIS LINE!!!!
               {
                  mm_best_free=ptr;
                  bestSize=*(ptr);
               }
            }
         }
         ptr+=(*ptr)+1;
      }
      if(bestSize!=0xFFFF)
      {
         ptr=mm_best_free;
         *(ptr-1)=(size_t)ctid;

         if((*ptr-size)>=MM_SPLIT_THRESH)
         {
            next=ptr+size+1;
            *(next++)=MM_FREE;
            *(next)=*ptr-size-MM_HEADER_SIZE;
            mm_try_join(next);

            *ptr=size;
         }
         if(ptr==mm_first_free+1)
            mm_update_first_free(ptr+*ptr+1);

      #ifdef CONF_TM
      LEAVE_KERNEL_CRITICAL_SECTION();
      #endif

         return (void*) (mm_best_free+1); //or (ptr+1)
      }
   #ifdef CONF_TM
   LEAVE_KERNEL_CRITICAL_SECTION();
   #endif

      return NULL;
   }
=================================================

the problem line has //THIS LINE!!!! written next to it to note it.  Originalyl
I had mm_best_free instead of bestSize, that the problem...



Message has 1 Reply:
  Re: My problems with adding a Best Fit algorithm for memory management to kernel/mm.c
 
(...) BTW, you can delete these two lines of intialization (i.e. lines 12 & 15 in the above function) as the intialized value gets clobbered on finding the first suitable sized block: 12) mm_best_free=ptr; 15) mm_best_free++; //this must point to (...) (21 years ago, 6-Dec-03, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  Re: My problems with adding a Best Fit algorithm for memory management to kernel/mm.c
 
(...) Fine. Could you please post the solution? I don't like unsolved riddles :) Regards, Michael (21 years ago, 6-Dec-03, to lugnet.robotics.rcx.legos)

14 Messages in This Thread:



Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR