...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stdlib.h> #include <string.h> void func(void) { size_t resize = 1024; size_t alignment = 1 << 12; int *ptr; int *ptr1; if ((ptr = (int *) aligned_alloc(alignment, sizeof(int))) == NULL) { /* Handle error */ } if ((ptr1 = (int *) aligned_alloc(alignment, resize)) == NULL) { /* Handle error */ } if ((memcpy(ptr1, ptr, sizeof(int)) == NULL) { /* Handle error */ } free(ptr); } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <malloc.h> void func(void) { size_t alignment = 1 << 12; int *ptr; int *ptr1; /* Original allocation */ if ((ptr = (int *) _aligned_malloc(sizeof(int), alignment)) == NULL) { /* Handle error */ } /* Reallocation */ if ((ptr1 = (int *) _aligned_realloc(ptr, 1024, alignment)) == NULL) { _aligned_free(ptr); /* Handle error */ } _aligned_free(ptr1); } |
...