-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_heap.c
48 lines (42 loc) · 2.11 KB
/
print_heap.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/******************************************************************************************
* *
* print_heap.c *
* *
******************************************************************************************/
// Team: Vaughn Johnson, Winter Meng
// print_heap visually displays the heap.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <inttypes.h>
#include <unistd.h>
#include "mem.h"
#include "mem_impl.h"
/******************************************************************************************
* *
* Procedure: print_heap *
* *
* Print a formatted listing on file f showing the blocks on the free list * *
* *
******************************************************************************************/
void print_heap(FILE * f) {
free_list_type * newptr;
free_list_type * lastptr;
newptr = freelistptr;
lastptr = NULL;
while (newptr != NULL) {
fprintf(f, "MemoryAddress = [%lu], ", (uintptr_t) newptr->address);
fprintf(f, "MemorySize = [%lu], ", (uintptr_t) newptr->size);
fprintf(f, "CellAddress = [%lu], ", (uintptr_t) newptr);
fprintf(f, "NextPointer = [%lu], ", (uintptr_t) newptr->nextNode);
fprintf(f, "PrevPointer = [%lu], ", (uintptr_t) newptr->prevNode);
if (newptr->prevNode == lastptr) {
fprintf(f, "PrevPointer Correct.\n");
} else {
fprintf(f, "PrevPointer Error.\n");
}
lastptr = newptr;
newptr = newptr->nextNode;
}
}