Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This non-compliant example shows that ptr is aligned to an alignment of 4096 bytes where as the realloc() function aligns the memory to a different alignment.
(Assuming that the sizeof(double) = 8 and sizeof(float) = 4.)

Code Block
bgColor#ffcccc
size_t size = 16;
size_t alignment = 1<<12;
float *ptr;
double *ptr1;

ptr = aligned_alloc(align , size);
ptr1 = realloc(ptr, size);

...

This compliant example checks that aligned_alloc() has the same alignment as the alignment realloc() function enforces on the memory pointed to by ptr.
(Assuming that the sizeof(double) = 8 and sizeof(float) = 4.)

Code Block
bgColor#ccccff
size_t size = 16;
size_t alignment = 1<<12;
float *ptr;
double *ptr1;

ptr = aligned_alloc(align , size);

if(align == alignof(ptr1)) {
ptr1 = realloc(ptr, size);
}

...