cmpsc330hw4/raii.h
Sandipsinh Rathod 0c92128fcf add raii stuff
2024-11-19 19:46:02 -05:00

27 lines
415 B
C

#ifndef RAII_H
#define RAII_H
#include "defs.h"
unsigned long allocatedMem = 0;
void *alloc(size_t size) {
void *ptr = malloc(size);
if (!ptr) {
pter "Memory allocation failed" << nl;
return NULL;
}
allocatedMem += 1;
return ptr;
}
void dealloc(void *ptr) {
if (ptr) free(ptr);
allocatedMem -= 1;
}
bool assert_alloc() {
return !allocatedMem;
}
#endif // RAII_H