Created
July 9, 2016 11:01
-
-
Save r-lyeh-archived/35375347478bfb6353f5b243f70529ed to your computer and use it in GitHub Desktop.
This file contains 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
/* Mike F */ | |
#include <stdint.h> | |
void *memalign( int align, size_t size ) { | |
void *mem = malloc( size + (align-1) + sizeof(void*) ); | |
if(!mem) return 0; | |
char *amem = ((char*)mem) + sizeof(void*); | |
amem += (align - ((uintptr_t)amem & (align - 1)) & (align-1)); | |
((void**)amem)[-1] = mem; | |
return amem; | |
} | |
void memfree( void *mem ) { | |
if(mem) free( ((void**)mem)[-1] ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment