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 / 3415
3414  |  3416
Subject: 
Re: Question about mm.C in BrickOS
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Wed, 13 Aug 2003 22:54:55 GMT
Viewed: 
3085 times
  
Hi,

1      if(*ptr>=size) {    // big enough?

Ptr points to the length byte of the first free block

2        *(ptr-1)=(size_t)ctid;  // set owner

*(ptr-1) actually is MM_FREE and is now set to the callers id.

5        if((*ptr-size)>=MM_SPLIT_THRESH) {

Now we can do two things: We could grab all memory we found in this
block or we could allocate only the memory we need. If the difference of
the actual free size and the allocated size is bigger than
MM_SPLIT_THRESH, we do the splitting process. For this, we have to build
up a new memory block structure directly behind the new allocated one.

6          next=ptr+size+1;

Next points behind the allocated block.

7          *(next++)=MM_FREE;

Mark this position with MM_FREE and advance with the pointer

8          *(next)=*ptr-size-MM_HEADER_SIZE;

Remember that *ptr has the actual size of the free block we are about to
split. *ptr - size gives the remaining free count at the end of the
block. *ptr - size - MM_HEADER_SIZE gives the free rest size in respect
of the fact that we built a new [MM_FREE, size-of-block] header. Write
this value to the size byte of the new memory block structure.

9          mm_try_join(next);

Look if a free block is found directly after the newly created free rest
and join both to one bigger free block.

11          *ptr=size;

Change the blocksize of the allocated block to the real one.

Have a close look at the beginning of mm.c. There, you can find the
memory layout of the block structure. Try to allocate a size-10 block in
a size-20 free area with pen and paper. That could help a lot in
understanding. Or even try to seperate the code, wrap it into a c
program and step through it with a debugger.

Regards,

Michael



Message has 2 Replies:
  Re: Question about mm.C in BrickOS
 
Thanks to both of you, I was pretty close to my understanding of it, but I did not know about the "new block creation behind the current block" but it makes sense now, if I have any other question (I am sure I will) I will def. ask. Thanks again, (...) (21 years ago, 14-Aug-03, to lugnet.robotics.rcx.legos)
  Re: Question about mm.C in BrickOS
 
(...) Michael I was reading through your reply you sent me a while back and I don't understand what that line in the code does and you explaination of it. I don't understand what is meant by pointing behind the block. Any help would be great thanks. (...) (21 years ago, 14-Sep-03, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  Question about mm.C in BrickOS
 
Hey My Senior Preoject where I update BrickOS is slowly taking shape (I am actually trying to do some now, but time is very limited). This project I am editing the Memory Managment Alg used by BrickOS. the first one I am going to add is Next Fit, it (...) (21 years ago, 13-Aug-03, to lugnet.robotics.rcx.legos)

7 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