Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void *my_malloc(size_t size)
- {
- char *unaligned;
- char *aligned;
- if (size == 0)
- return NULL;
- unaligned = malloc(size+16);
- if (unaligned == NULL)
- return NULL;
- aligned = (char *)((intptr_t)(unaligned + 16) & ~15);
- aligned[-1] = (char)(unaligned - aligned);
- return aligned;
- }
- void my_free(void *aligned)
- {
- if (aligned == NULL)
- return;
- free(aligned - aligned[-1]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement