Created
January 3, 2015 22:32
-
-
Save ChuckM/a3821d18d741d7586cf8 to your computer and use it in GitHub Desktop.
Simple node allocator / freer
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
struct debug_data { | |
char *data; | |
struct debug_data *nxt; | |
} | |
struct debug_data *root; // all of the debug chunks | |
... | |
... | |
new_debug_data(char *dbg_string) { | |
struct debug_data *n; | |
n = (struct debug_data *)(malloc(sizeof(struct debug_data) + strlen(dbg_string)); | |
if (n == NULL) return; // no more memory | |
n->data = (char *)(n + sizeof(struct debug_data)); | |
strcpy(dbg_string, n->data); | |
n->nxt = root; | |
root = n; | |
return; | |
} | |
void | |
free_all_debugs(void) { | |
while (root) { | |
cur = root; | |
root = root->nxt; | |
free(cur); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment