alignment guarantees from realloc(3)

Alejandro Colomar alx@kernel.org
Thu Oct 30 23:29:25 GMT 2025


Hi!


A discussion in the C++ std-proposals@ mailing list triggered a
discussion about the lack of aligned_realloc().

I don't think we want an aligned_realloc(), as it would be very weird to
change the alignment of a block of memory.  Once you have there some
contents, the alignment would just have to be preserved.

Thus, I think realloc(3) should preserve the alignment from a previous
aligned_alloc(3), and thus, not need an aligned_realloc() at all.

Before writing a proposal for the standards, I'd like to ask about the
feasibility of adding this guarantee in realloc(3) in glibc and musl.
Would you mind adding such a guarantee to realloc(3)?

The precise wording I'm considering for a standards proposal will look
something like this:

	realloc(3) shall preserve the alignment of a block allocated
	previously by aligned_alloc(3).


Have a lovely night!
Alex

-- 
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20251031/40d8e092/attachment-0001.sig>


More information about the Libc-alpha mailing list