-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmem.c
51 lines (35 loc) · 725 Bytes
/
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
#include "include.h"
#include "mem.h"
#ifdef WATCH_MEMORY
static int stats_alloc = 0, stats_freed = 0, stats_alloc_b = 0;
void* w_malloc (size_t s)
{
// printf(" ~~~~~~~~~~~ allocating %d bytes ~~~~~~~~~~~~~\n", s);
stats_alloc++;
stats_alloc_b += s;
return malloc(s);
}
void w_free (void* b)
{
stats_freed++;
free(b);
}
void memory_stats()
{
printf("\n"
" =+= Memory stats =+= \n"
" > Allocated: %d blocks (%d bytes)\n"
" > Freed: %d blocks\n"
" > Left: %d blocks\n"
"\n",
stats_alloc, stats_alloc_b,
stats_freed,
stats_alloc - stats_freed);
}
#endif
extern void* w_dup (void* d, size_t s)
{
void* o = w_malloc(s);
memcpy(o, d, s);
return o;
}