-
Notifications
You must be signed in to change notification settings - Fork 0
/
mem.c
executable file
·73 lines (51 loc) · 1.43 KB
/
mem.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
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
#include "mem.h"
#include <stdlib.h>
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static uint64_t totalMemory = 0;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void *Malloc(size_t size)
{
void *pointer = malloc(size);
if(pointer == NULL)
{
fprintf(stderr, "Error allocating %zu bytes.\n", size);
exit(1);
}
totalMemory += size;
return pointer;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void *Calloc(size_t nmemb, size_t size)
{
void *pointer = calloc(nmemb, size);
if(pointer == NULL)
{
fprintf(stderr, "Error allocating %zu bytes.\n", size);
exit(1);
}
totalMemory += nmemb * size;
return pointer;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void *Realloc(void *ptr, size_t size, size_t additionalSize)
{
void *pointer = realloc(ptr, size);
if(pointer == NULL)
{
fprintf(stderr, "Error allocating %zu bytes.\n", size);
exit(1);
}
totalMemory += additionalSize;
return pointer;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Free(void *ptr)
{
free(ptr);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uint64_t TotalMemory()
{
return totalMemory;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -