Original Post
I've written a macro which is used in class declarations, which simply defines a static new operator method. However, it's a bit messy as its signature looks a bit like this: Class CClass { public: // public constructors, destructors and methods etc ALIGN_OPERATOR_NEW // macro which defines the new operator }; const int CACHE_LINE = 32; // align heap class arrays on the 32 bit cache line. const int SIZE = 10; // size of the array. CClass *pClass = new (CACHE_LINE, SIZE) CClass [SIZE]; As you can see I had to make use of the SIZE constant twice. Messy yes! The reason? Well, during runtime, the Visual C++ Express 2005 complier seems to produce code that allocates extra bytes during a call to new. Even custom made new operators. I assume this is down to the virtual pointer (dependent upon the class of course) as well as for various other house-keeping duties in order to properly de-allocate the array during a subsequent delete [] call. Hence, I don't quite get perfectly aligned class arrays on the heap. Even when I use the _aligned_offset_malloc function. (Or was it _align_offset_malloc? I'm not on my home computer here!) Anyway, I've introduce the SIZE argument into the new operator, so that I can perform a simple operation which allows me to align the class array on the heap properly. I would sure appreciate it if someone could tell me if there's a neater way of doing this. Or if they could tell me what exactly goes on behind the scenes during runtime, when complex classes are allocated on the heap using operator new.