H09 Practice Soln

F static int cmpaddrconst void a const void b return

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: ocks are at front, which creates worst-case situation for FindBlock. f) static int CmpAddr(const void *a, const void *b) { return **(void ***)a - **(void ***)b; } –3– void CompactHeap() { void **refs[nMasters]; int count = 0; for (int i = 0; i < nMasters; i++) // make arr of ref to masters if (masters[i]) refs[count++] = &masters[i]; qsort(refs, count, sizeof(void **), CmpAddr); } header *cur = heapStart; // cur points to next hdr in heap for (int i = 0; i < count; i++) { header *hdr = (header *)*refs[i] - 1; size_t nWords = (*hdr & SIZE_MASK); memmove(cur, hdr, nWords*sizeof(header)); // m...
View Full Document

Ask a homework question - tutors are online