142. Code malloc() in C
Microsoft Interview Questions and Answers
(Continued from previous question...)
142. Code malloc() in C
Question:
Code malloc() in C
maybe an answer:
1 solution, you can have 2 linked lists: Free List , occupied list. Initially the free list contains one cell with data= total capacity of available. once a request comes(malloc), one entry is added occupied list with size=request_size, and offset of memory location. The poiter is returned using the offset value stored.
Once a Free is encountered, Free list is added with size, offset value.
Malloc will search through free list of size and will also modify the free list(size) if a block is found and allocated.
(Continued on next question...)
Other Interview Questions
|