diff options
author | jdlugosz963 <jdlugosz963@gmail.com> | 2023-03-01 23:30:31 +0100 |
---|---|---|
committer | jdlugosz963 <jdlugosz963@gmail.com> | 2023-03-01 23:30:31 +0100 |
commit | f44f1f8c7ef7b6266667dce76db686af3258adfc (patch) | |
tree | e0775e2a07713f1ac23d37b5271340fe8cbebd16 /memory.c | |
download | jadl-f44f1f8c7ef7b6266667dce76db686af3258adfc.tar.gz jadl-f44f1f8c7ef7b6266667dce76db686af3258adfc.zip |
Build simple abstract syntax tree
Diffstat (limited to 'memory.c')
-rw-r--r-- | memory.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/memory.c b/memory.c new file mode 100644 index 0000000..387268b --- /dev/null +++ b/memory.c | |||
@@ -0,0 +1,27 @@ | |||
1 | #include "memory.h" | ||
2 | |||
3 | #include <stdio.h> | ||
4 | |||
5 | void *jadl_malloc(size_t size) { | ||
6 | void *ptr = malloc(size); | ||
7 | if(ptr == NULL) | ||
8 | { | ||
9 | printf("malloc: ERROR"); | ||
10 | exit(1); | ||
11 | } | ||
12 | return ptr; | ||
13 | } | ||
14 | |||
15 | void jadl_free(void *ptr) { | ||
16 | return free(ptr); | ||
17 | } | ||
18 | |||
19 | long usage() { | ||
20 | struct rusage r_usage; | ||
21 | getrusage(RUSAGE_SELF, &r_usage); | ||
22 | return r_usage.ru_maxrss; | ||
23 | } | ||
24 | |||
25 | void usage_print() { | ||
26 | printf("Mem usage: %ld kilobytes\n", usage()); | ||
27 | } | ||