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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux