Some questions on c99, gcc, and multi-dimensional dynamic arrays

John (Eljay) Love-Jensen eljay@adobe.com
Fri Dec 4 14:21:00 GMT 2009


Hi Axel & Cedric,

malloc returns a pointer with "worst case scenario" alignment, suitable for any of the basic data types.

On some platforms, malloc has an even stronger alignment guarantee.  Such that the alignment is suitable for any SIMD type (such as AltiVec or MMX/SSE alignment requirements).

I'm not aware of any platform where malloc will return memory with even more stringent alignment requirements, such as page-aligned for PMMU or I/O DMA purposes.  For those kinds of alignment requirements, the programmer has to take special care -- which is probably very platform specific and using OS API calls (or on a barebones no-OS platform, all in the hands of the meticulous programmer) rather than Standard C Library calls.

PERSONALLY, I wish it was void* malloc(size_t size, size_t alignment), or at least a Standard C Library one in addition to the standard malloc.  But it's not, and if it were it'd probably make code worst-case-scenario cross-platform pessimized.  C'est la vie.

Sincerely,
--Eljay



More information about the Gcc-help mailing list