This preview shows page 1. Sign up to view the full content.
Unformatted text preview: moving any blocks. However, the C language poses some interesting challenges for the implementation of the isPtr function. First, C does not tag memory locations with any type information. Thus, there is no obvious way for isPtr to determine if its input parameter p is a pointer or not. Second, even if we were to know that p was a pointer, there would be no obvious way for isPtr to determine whether p points to some location in the payload of an allocated block. One solution to the latter problem is to maintain the set of allocated blocks as a balanced binary tree that maintains the invariant that all blocks in the left subtree are located at smaller addresses and all blocks in the right subtree are located in larger addresses. As shown in Figure 10.55, this requires two additional ﬁelds (left and right) in the header of each allocated block. Each ﬁeld points to the header of some allocated block.
allocated block header size <= left right > remainder of block Figure 10.55: Left and right pointers in a balanced tree of allocated blocks. The isPtr(ptr p) function uses the tree to perform a binary search of...
View Full Document
This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.
- Spring '10
- The American