-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
49 lines (39 loc) · 1.04 KB
/
main.cpp
File metadata and controls
49 lines (39 loc) · 1.04 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
#include <iostream>
#include "malloc.h"
int main() {
int* location = static_cast<int*>(myMalloc(4 * sizeof(int)));
if (location == NULL) {
std::cerr << "Memory allocation failed\n";
return 1;
}
printf("Memory allocated at: %p\n", location);
location[0] = 69;
for (int i = 0; i < 4; i++) {
location[i] = 69 + i;
}
for (int i = 0; i < 4; i++) {
printf("%d\n", location[i]);
}
debugHeap();
myFree(location);
std::cout << "Freed first pointer\n";
debugHeap();
int* location2 = static_cast<int*>(myMalloc(4 * sizeof(int)));
if (location2 == NULL) {
std::cerr << "Memory allocation failed\n";
return 1;
}
printf("Memory allocated at: %p\n", location2);
location2[0] = 169;
for (int i = 0; i < 4; i++) {
location2[i] = 169 + i;
}
for (int i = 0; i < 4; i++) {
printf("%d\n", location2[i]);
}
debugHeap();
myFree(location2);
std::cout << "Freed second pointer\n";
debugHeap();
return 0;
}