So let's say I have the following object with a few private members
/* Excluding constructors, member functions, etc. */
double * m_elements;
If this LAvector object is dynamically allocated itself, isn't it true that the byte alignment of the m_elements array could be off (even if mkl_malloc was used to dynamically allocate the internal member m_elements)? Would I have to write an aligned new operator for this LAvector object?
Also if the LAvector object is used as an element for an STL vector, etc, wouldn't I also need a special LAvector object allocator?
Thanks for your time.
Possibly you can have some clarification on the problem? My understanding that the class memory 'm_elements' is used by MKL function call, and it the memory is allocated by mkl_malloc (), the question is if the class still need to be allocated by mkl_malloc(), and make sure the address for the class is also aligned with 16 bytes?
If MKL function only use 'm_elements', it is not required that the class itself is aligned with 16 bytes, the alignment for 'm_elements' address will be fine.
Thanks for the response.
Yes, m_elements is the C style array that will be passed to the mkl functions. LAVector is a just a class wrapper around the array of data.
I wasn't sure what happens to the alignment of the m_elements array if the LAVector class is defined dynamically. For example:
vector1 = new LAVector(4);
Since m_elements is a member of LAVector, I wanted to be sure that the allocation of LAVector didn't cause m_elements member to be off on its byte alignment. I also wanted to be sure that m_elements isn't off of alignment if the following happens:
The reason being here that the LAVector is being allocated by std::vector's default allocator when it's placed into the vector.
Please confirm that the byte alignment of m_elements would be ok in these two situations.
Even if LAVector is dynamically allocated it is still programmer's responsibility to allocate memory for the m_elements (in the constructor). Am I correct?
As Chao suggests you can allocate m_elements using mkl_alloc() and m_elements will be properly aligned. The class object itself can be allocated in any way you prefer.
I hope that helps,
You are correct. It doesn't matter if the LAVector object is statically or dynamically allocated, regardless the m_elements member must have its array elements dynamically allocated during construction.
I think this answers my question.