Writing a memory manager: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
mNo edit summary
m Partial revert of 0xjarno's changes. I don't have a problem with numbering but it messed up the layout.
Line 25:
 
How do we find a free block? (this is for a first fit method with a header, but for a basic buddy system all you need is some imagination)
#* Start with a pointer to the beginning of the free memory
##* Does this header have an End Of Memory status?
##** Yes
###*** Allocate a new page
##**:or
###*** return an error (such as a pointer to 0)
#*Does this header say this memory is free
##**Yes
###***Is (address of next header - (address of this header - size of header)) larger than the size wanted
####****Yes?
#####*****WE FOUND A FREE BLOCK!!!!
####****No?
#####*****Point to the next block and go back to step 2
##**No
###***Point to the next block and go back to step 2
 
Once you have found one, set it's used bit to used. If the space found is significantly larger than the space needed, then it is generally a good idea to split it up (cut it in half, then half again, or add another header right after the used space and update the pointers.. use your imagination!) ;] Then return the address!