Search code examples
c++directxdirectx-10

How can I utilise a vector in a method call that requires an array?


For example, this method:

memcpy(pVoid, MyStructArray, sizeof(MyStructArray)); 

This used to be fine because I was calling this method once on instantiation where the array was sa pre-defined size. However it became necessary to change the information in the 'array' dynamically, so I'm using a vector instead. Is the information in a vector guaranteed to be contiguous?

could I do something like

 memcpy(pVoid, &MyStructVector, sizeof(*MyStructVector) * MyStrucVector.size()); 

Solution

  • The data in a std::vector is contiguous. But you can't copy it like you are doing. You can, however, do this:

    memcpy(pVoid, &MyStructVector[0], sizeof(MyStructVector[0]) * MyStrucVector.size());