Interview Questions

My application depends heavily on dynamic allocation of nodes for data structures

C Interview Questions and Answers


(Continued from previous question...)

My application depends heavily on dynamic allocation of nodes for data structures

Q: My application depends heavily on dynamic allocation of nodes for data structures, and malloc/free overhead is becoming a bottleneck. What can I do ?

A:One improvement, which is particularly attractive if all nodes are the same size, is to place unused nodes on your own free list, rather than actually freeing them. (This approach works well when one kind of data structure dominates a program's memory use, but it can cause as many problems as it solves if so much memory is tied up in the list of unused nodes that it isn't available for other purposes.)

(Continued on next question...)

Other Interview Questions