Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Align memory of desired multiple number address (except prime ) allocated*/
- #include <stdlib.h>
- #include<stdio.h>
- void *allign_alloc(size_t allign ,size_t bytes)
- {
- size_t *book = NULL ;
- const size_t total_size = bytes+allign+sizeof(size_t );
- char *data = (char *)malloc(sizeof(char)*total_size) ;
- const void * const data_row = data ;
- data = data + sizeof(size_t) ;
- const size_t offset = allign - ((size_t)data%allign) ;
- data+=offset ;
- book = (size_t*)data - sizeof(size_t );
- *book = (size_t )data_row ;
- return data ;
- }
- int main()
- {
- int *ptr = allign_alloc(7,30) ;
- printf("\n%s\n%u",(char*)((((size_t)ptr%7)==0)?"Yes":"NO"),(unsigned)ptr) ;
- getchar();
- free((void*)*(ptr-sizeof(size_t))) ;
- return 0 ;
- }
Add Comment
Please, Sign In to add comment