memory-test.c 1.58 KB
Newer Older
cdf009's avatar
cdf009 committed
1 2 3 4 5 6 7 8 9
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include "dnode.h"
#include "dlist.h"
#include "allocator.h"



cdf009's avatar
cdf009 committed
10 11
struct dnode* opt1;
struct dnode* opt2;
cdf009's avatar
cdf009 committed
12 13 14 15 16 17 18 19 20 21 22
struct dnode* opt3;


int main(){

  struct dnode* options;

  allocator_init(1000);
  printf("\n");
  printf( "First Fit: ");
  printf("\n");
cdf009's avatar
cdf009 committed
23
  printf("Allocating 400");
cdf009's avatar
cdf009 committed
24
  printf("\n");
cdf009's avatar
cdf009 committed
25
  options = allocate(400, 0);
cdf009's avatar
cdf009 committed
26 27 28 29 30
  allocator_print();

  printf("\n");
  printf("Allocating 300");
  printf("\n");
cdf009's avatar
cdf009 committed
31
  opt1 = allocate(300, 0);
cdf009's avatar
cdf009 committed
32 33 34 35 36
  allocator_print();

  printf("\n");
  printf("D-Allocating 300");
  printf("\n");
cdf009's avatar
cdf009 committed
37
  deallocate(opt1->data);
cdf009's avatar
cdf009 committed
38 39 40 41 42
  allocator_print();

  printf("\n");
  printf("Allocating 800");
  printf("\n");
cdf009's avatar
cdf009 committed
43
  allocate(800, 0);
cdf009's avatar
cdf009 committed
44 45
  allocator_print();
  printf("No change because there is not enough memory");
cdf009's avatar
cdf009 committed
46 47 48
  printf("\n");
  printf("\n");

cdf009's avatar
cdf009 committed
49 50 51 52 53 54


  allocator_init(1000);
  printf("\n");
  printf( "Best Fit: ");
  printf("\n");
cdf009's avatar
cdf009 committed
55
  printf("Allocating 500");
cdf009's avatar
cdf009 committed
56
  printf("\n");
cdf009's avatar
cdf009 committed
57
  opt1 = allocate(500, 1);
cdf009's avatar
cdf009 committed
58 59 60
  allocator_print();

  printf("\n");
cdf009's avatar
cdf009 committed
61
  printf("Allocating 200");
cdf009's avatar
cdf009 committed
62
  printf("\n");
cdf009's avatar
cdf009 committed
63
  opt2 = allocate(200, 1);
cdf009's avatar
cdf009 committed
64 65 66
  allocator_print();

  printf("\n");
cdf009's avatar
cdf009 committed
67
  printf("D-Allocating 200");
cdf009's avatar
cdf009 committed
68
  printf("\n");
cdf009's avatar
cdf009 committed
69
  deallocate(opt2->data);
cdf009's avatar
cdf009 committed
70 71 72 73 74 75 76 77 78
  allocator_print();


  allocator_init(1000);
  printf("\n");
  printf( "Worst Fit: ");
  printf("\n");
  printf("Allocating 300");
  printf("\n");
cdf009's avatar
cdf009 committed
79
  opt1 = allocate(300, 2);
cdf009's avatar
cdf009 committed
80 81 82
  allocator_print();

  printf("\n");
cdf009's avatar
cdf009 committed
83
  printf("Allocating 100");
cdf009's avatar
cdf009 committed
84
  printf("\n");
cdf009's avatar
cdf009 committed
85
  opt2 = allocate(100, 2);
cdf009's avatar
cdf009 committed
86 87 88
  allocator_print();

  printf("\n");
cdf009's avatar
cdf009 committed
89
  printf("D-Allocating 100");
cdf009's avatar
cdf009 committed
90
  printf("\n");
cdf009's avatar
cdf009 committed
91
  deallocate(opt2->data);
cdf009's avatar
cdf009 committed
92 93
  allocator_print();

cdf009's avatar
cdf009 committed
94
return 0;
cdf009's avatar
cdf009 committed
95 96

}