This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC #define for alignment


Hi Duane,

> Suggestions? Sure I could use sizeof(void *) also..

As long as you are writing your own malloc routine, why not add an alignment parameter?

I was always a bit irked that malloc did not provide an alignment parameter.  Sometimes you need PMMU alignment (256 alignment, I think), or AltiVec or MMX/SSE alignment (16 alignment), or CreateFile FILE_FLAG_NO_BUFFERING (4096 alignment on x86, or 8192 alignment on x86_64), et cetera.

extern void* MyMalloc(size_t byteSize, size_t alignment);
typedef char byte;
byte* buffer = (byte*)MyMalloc(81920, 4096); // 80KB, with 4KB alignment
long double* pLongDouble = (long double*)MyMalloc(100 * sizeof(long double), sizeof(long double)); // 100 long doubles, with long double alignment
SuperStruct* pSuperStruct = (SuperStruct*)MyMalloc(100 * sizeof(SuperStruct), sizeof(void*)); // 100 SuperStruct, with regular pointer apropos alignment.

Just a thought.

Sincerely,
--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]