Why Dynamic Memory Allocation P734 1 #include "csapp. h" 2 #define MAXN 15213 4 int array [maxn]i 6 int main o int i ni 10 scanf("d", &n)i 11 f(n> MAXN) 12 app error(" Input fi1et。。big") for(i=0;主<n;i++) 14 scanf("d", &array [il)i exit(o)i
11 1 #include "csapp.h" 2 #define MAXN 15213 3 4 int array[MAXN]; 5 6 int main() 7 { 8 int i, n; 9 10 scanf("%d", &n); 11 if (n > MAXN) 12 app_error("Input file too big"); 13 for (i = 0; i < n; i++) 14 scanf("%d", &array[i]); 15 exit(0); 16 } Why Dynamic Memory Allocation P734
Why dynamic Memory Allocation P734 1 #include "csapp. h 3 int main() 4 int *array, i, ni scanf("号d",&n); 8 array ( int *) Malloc(n sizeof (int))i for (i=0: i< n i++) 10 scanf(d, &array[i]) 11 exit(o)i 12} 12
12 1 #include "csapp.h" 2 3 int main() 4 { 5 int *array, i, n; 6 7 scanf("%d", &n); 8 array = (int *)Malloc(n * sizeof(int)); 9 for (i = 0; i < n; i++) 10 scanf("%d", &array[i]); 11 exit(0); 12 } Why Dynamic Memory Allocation P734
10.9.3 Allocator Requirements and Goals
13 10.9.3 Allocator Requirements and Goals
Constraints Applications: Can issue arbitrary sequence of allocation and free requests Free requests must correspond to an allocated block
14 Constraints • Applications: – Can issue arbitrary sequence of allocation and free requests – Free requests must correspond to an allocated block
Constraints Allocators Can 't control number or size of allocated blocks Must respond immediately to all allocation requests i.e., can't reorder or buffer requests Must allocate blocks from free memory i. e, can only place allocated blocks in free memory 15
15 Constraints • Allocators – Can’t control number or size of allocated blocks – Must respond immediately to all allocation requests • i.e., can’t reorder or buffer requests – Must allocate blocks from free memory • i.e., can only place allocated blocks in free memory