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:
|
4219 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:
Message is in Reply To:
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
|
|
|
|