Created
January 21, 2013 10:59
-
-
Save diegostamigni/4585283 to your computer and use it in GitHub Desktop.
memagent.h used in Viron.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef __MEMAGENT_H | |
#define __MEMAGENT_H | |
#include <stdarg.h> | |
#include <stdlib.h> | |
#include <sys/conf.h> | |
// safe free with the checks if ptr exist | |
// before cleaning | |
static inline void safefree(void *ptr) { | |
if (ptr) return free(ptr); | |
} | |
// dealloc takes args as parameters, and dealloc those | |
// be careful by using this function | |
static inline void dealloc(void *args, ...) { | |
va_list p; va_start(p, args); | |
for (void *v = args; v; v = va_arg(p, void *)) | |
safefree(v); | |
va_end(p); | |
} | |
// release x long size | |
static inline void release(void **x, size_t size) { | |
for (register int i = 0; i < size; i++) | |
safefree(*(x+i)); | |
} | |
#endif /* MEMAGENT_H */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment