This preview shows page 1. Sign up to view the full content.
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
This note was uploaded on 02/06/2014 for the course CS 106X taught by Professor Cain,g during the Winter '08 term at Stanford.
- Winter '08