{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

H09 Practice Soln

Comparing headers as signed ints will make the size

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: the value negative in signed interpretation. Comparing headers as signed ints will make the size of in-use blocks appear negative and freed as positive, exactly what is desired here. The hdr is unsigned and nWords is a size_t (also unsigned) so both must be cast to signed int for the comparison to be done using signed types: (int)(*hdr) >= (int)nWords d) void **NewHandle(size_t nPayloadBytes) { header *hdr = FindBlock(NumWords(nPayloadBytes)+1); // +1 for hdr int index = FindMaster(); if (hdr == NULL || index == -1) return NULL; *hdr |= INUSE_MASK; // mark block header as in-use masters[index] = hdr + 1; // handle points to payload return &masters[index]; } e) Possible factors to consider: • F indMaster has better locality of reference as masters are accessed in a contiguous array and only miss cache when crossing the cache line, whereas FindBlock is jumping t...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online