Writing a memory manager: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
No edit summary
Line 33:
*** 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!