I was reading through a C++ template whose purpose was to allocate memory blocks (_type_ is the generic type passed). It seems to me the purpose of this code would be to create a byte aligned buffer to store a _type_ object, but I am confused as to why, since buffer is not a pointer, the other elements are not.
Code:#define CONST_MAX( x, y ) ( (x) > (y) ? (x) : (y) ) #define BLOCK_ALLOC_ALIGNMENT 16 ... union element_t{ _type_* data; // this is a hack to make sure the save game system marks _type_ as saveable element_t* next; byte buffer[(CONST_MAX(sizeof( _type_ ), sizeof(element_t *)) + (BLOCK_ALLOC_ALIGNMENT - 1)) & ~(BLOCK_ALLOC_ALIGNMENT - 1)]; };



4Likes
LinkBack URL
About LinkBacks



