-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.c
More file actions
51 lines (45 loc) · 990 Bytes
/
Copy pathutility.c
File metadata and controls
51 lines (45 loc) · 990 Bytes
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
/**
* @file utility.c
* @author Julian Martinez del Campo
* @brief this file implements utility.h
*/
#include <stdlib.h>
#include "utility.h"
static unsigned long _memory_usage = 0;
/**
* Calloc
*
* This funciton is a wrapper to calloc. It checks that memory was
* properly allocated, and tracks memory usage
*
* @param the number of elements in the array
* @param size the size of the element
* @return a pointer to the allocated memory
*/
void * Calloc( size_t nmemb, size_t size )
{
_memory_usage += (nmemb * size);
return calloc( nmemb, size );
}
/**
* Free memory
*
* Frees memory, and decreases the memory usage tracked accordingly
*
* @param ptr to memory to free
* @param size the size of the memory to free
*/
void Free( void * ptr, size_t size )
{
_memory_usage -= size;
free( ptr );
}
/**
* Get the memory used by the program
*
* @return the memory used, in bytes
*/
unsigned long memory_usage( void )
{
return _memory_usage;
}