-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest7.c
42 lines (36 loc) · 818 Bytes
/
test7.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
#include <stdlib.h>
#include <stdio.h>
#include "MyMalloc.h"
int allocations =10000;
int
main( int argc, char **argv )
{
printf("\n---- Running test7 ---\n");
printf("Allocate many objects\n");
char * ptrs[15410];
int i;
for (i = 0; i < allocations; i++ ) {
char * p1 = (char *) malloc(100 );
ptrs[i] = p1;
*p1 = 100;
}
print_list();
printf("----------- Free even ---------------\n");
for(i = 0; i<allocations; i = i+2){
free(ptrs[i]);
}
print_list();
printf("------------ Free odd ----------------\n");
for(i = 1; i<allocations; i = i+2){
free(ptrs[i]);
}
print_list();
printf("---- Allocate 100 blocks ----\n");
for (i = 0; i < allocations; i++ ) {
char * p1 = (char *) malloc(100 );
ptrs[i] = p1;
*p1 = 100;
}
print_list();
exit( 0 );
}