Start with a large array of bytes to use as a buffer. Keep a list of pointers to blocks of available memory.
Malloc will look through the list for a large enough available block. It will actually need 4 more bytes than the size of the requested block and update the size of that block in the list. It will store the size of the block in the first four bytes and return a pointer to the 5th byte. Free will look through the list to determine if the freed block is adjacent to a block in the list. If so, it will enlarge that block. Otherwise it will add the block as a new element in the list. This makes the memory available to be used by another call to malloc. Don On Dec 19, 11:32 am, Anuj Khandelwal <[email protected]> wrote: > Hi, > How can we implement our own Malloc() and free() function ? > > -- > Anuj Khandelwal > Final Year Undergraduate Student > Department of Computer Engineering > Malaviya National Institute of Technology, Jaipur > India > +91-9711088177 --
