Skip to content

Instantly share code, notes, and snippets.

@ChuckM
Created January 3, 2015 22:32
Show Gist options
  • Save ChuckM/a3821d18d741d7586cf8 to your computer and use it in GitHub Desktop.
Save ChuckM/a3821d18d741d7586cf8 to your computer and use it in GitHub Desktop.
Simple node allocator / freer
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