[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] _kmr_get()



Hi Michael!

> In the function _kmr_get() in kmemory.c, there's some code that
> reads something like this:
> 
> begin:
>     - get the next free memory region pointer
>     - remove the memory region pointer from the free list
>     - initialize the memory region pointer
>     - IF there are no more free memory region pointers on this page
>         THEN look for next free memory region pointer on other pages
>         IF no free memory region pointers were found on other pages
>             THEN allocate another page for memory region pointers
>             IF a page could be allocated
>                 THEN GOTO begin
>             ELSE
>                 Re-attach the free block
>                 return NULL
>      - Return a pointer to the memory region
> 
> My questions:
> 
> 1)  Why do we re-try once we allocate a new page?  Don't we already
>     have a region pointer?  What happens to the detached region pointer?

For page allocation we need a memory region descriptor. So if there are no
free descriptors we can't allocate a new page. So it must be granted that
there is at least one free descriptor if we enter _kmr_get.

This avoids any recursion problems because _kmr_get allocate a page
through get_region that is mostly called from get_region.

> 2)  Why are we returning NULL even though a free region pointer exists?
> 3)  Wouldn't it be better to put the existence check at the beginning
>     rather than the middle?

Clear now?


Tschuess
   ...Frank

--
ATARI FALCON 040 // MILAN 040
--------------------------------------
Internet: fnaumann@cs.uni-magdeburg.de
Mausnet:  Frank Naumann @ L2