0

In VS c++ I am allocating a CComSafeArray and need the data array behind to be 32 byte aligned. How do I do that. It is not a solution to align the CComSafeArray itself because that does not align the data array behind.

  • Sounds like an [XY problem](http://xyproblem.info/). Why, exactly, do you believe you need such an alignment, and why does it have to be a safearray? What actual problem are you trying to solve? – Igor Tandetnik May 10 '16 at 14:32
  • Hi. The COM interface is on an embedded system and I need to read some memory in the embedded system. I need the read to be fast and use DMA from the HW. The DMA transfer from the memory requires the the destination of the DMA is 32 byte aligned. The SafeArray is needed to avoid copying the data more that absolutely necessary. The interface function is something like STDMETHODIMP CServer::ReadMemory(DestType SubSys, DWORD RelAddr, DWORD Size8, SAFEARRAY** data, RtnCode* result) – Jens Mose Pedersen May 11 '16 at 08:50
  • Is it an out-of-proc server? If so, realize that the memory is copied anyway, during marshaling across process boundary. If it's an in-proc server - does it really have to be a COM server to begin with (as opposed to, say, a plain C-style API exposed from a DLL)? You won't have a sufficiently fine control over memory allocation with CoTaskMemAlloc et al. – Igor Tandetnik May 11 '16 at 13:35
  • Upon further consideration, your best bet is probably to have the server allocate shared memory (see `CreateFileMapping` et al) and use COM only to communicate its handle or name to the client. I'm pretty sure shared memory is 4K aligned. COM is good at command-and-control, not so good at shuffling large amounts of data around. – Igor Tandetnik May 11 '16 at 15:20
  • Now the interface is COM and that not changed for this problem. – Jens Mose Pedersen May 12 '16 at 12:09

0 Answers0