This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: GCC #define for alignment
- From: "John (Eljay) Love-Jensen" <eljay at adobe dot com>
- To: Duane Ellis <duane at duaneellis dot com>, GCC-help <gcc-help at gcc dot gnu dot org>
- Date: Wed, 3 Dec 2008 05:18:42 -0800
- Subject: 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