-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
76 lines (73 loc) · 1.64 KB
/
main.c
File metadata and controls
76 lines (73 loc) · 1.64 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
** main.c for malloc in /home/docqui_a/work/PSU_2015_malloc/v2/
**
** Made by Avel Docquin
** Login <docqui_a@epitech.net>
**
** Started on Tue Feb 9 18:43:07 2016 Avel Docquin
** Last update Sun Feb 14 23:03:28 2016 Avel Docquin
*/
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
int main() {
int i;
int random;
i = 0;
int *ptr_one;
int *ptr_two;
if ((ptr_one = (int *)realloc(NULL, 100000000)) == NULL) {
printf("ERROR: Out of memory\n");
return 1;
}
printf("ptr_one = %p\n", ptr_one);
*ptr_one = 25;
if ((ptr_one = realloc(ptr_one, 100)) == NULL) {
printf("ERROR: Out of memory\n");
return 1;
}
printf("realloc\n");
*ptr_one = 250;
printf("%d\n", *ptr_one);
if ((ptr_two = (int *)malloc(sizeof(int))) == 0) {
printf("ERROR: Out of memory\n");
return 1;
}
*ptr_two = 40;
printf("%d\n", *ptr_two);
printf("sbrk: %p\n", sbrk(0));
free(ptr_one);
srand(time(NULL));
while (i < 10) {
random = rand() % 10000;
malloc(random);
random = (random - 1) / 4 * 4 + 4;
printf("m[%d]: %d\n", i, random);
++i;
}
/*printf("1st brk = %p\n", sbrk(0));
realloc(NULL, 0);
show_alloc_mem();
char *str = malloc(0);*/
/*printf("%d\n", BLOCK_SIZE);
printf("%p\n", block->ptr);
printf("%p\n", block);*/
/*char *str1 = malloc(16);
char *str2 = malloc(32);
char *str3 = malloc(2047);
show_alloc_mem();*/
/*free(str);
show_alloc_mem();
malloc(240);
show_alloc_mem();
free(str2);
realloc(str2, 10000);
show_alloc_mem();
free(str1);
char *str4 = malloc(14);
show_alloc_mem();
free(str4);
show_alloc_mem();*/
return (0);
}