Re: GCC #define for alignment

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

 



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 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