Does realloc allocate memory allocated by C11 aligned_alloc alignment?

Consider the following (C11) code:

void *ptr = aligned_alloc(4096, 4096); ... // do something with 'ptr' ptr = realloc(ptr, 6000); 

Since the memory pointed to by ptr has a 4096 byte alignment from aligned_alloc , will it (read: this is guaranteed) keep that alignment after a (successful) call until realloc ? Or will memory revert to default alignment?

+6
source share
1 answer

Alignment is not supported by the pointer. When you call realloc, you can only rely on the alignment that realloc guarantees. You will need to use aligned_alloc to perform any redistributions.

+4
source

Source: https://habr.com/ru/post/959126/


All Articles