In short, I am wondering if there is an auto_ptr like type for arrays. I know I could roll my own, I\'m just making sure that there isn\'t already something out there.
Use
std::vector<BYTE> buffer(cbType);
pType = (WM_MEDIA_TYPE*)&buffer[0];
or since C++11
std::vector<BYTE> buffer(cbType);
pType = (WM_MEDIA_TYPE*)buffer.data();
instead.
Additional: If someone is asking if the Vectors are guaranteed to be contiguous the answer is Yes since C++ 03 standard. There is another thread that already discussed it.
If C++11 is supported by your compiler, unique_ptr can be used for arrays.
unique_ptr<BYTE[]> buffer(new BYTE[cbType]);
pType = (WM_MEDIA_TYPE*)buffer.get();
There is nothing for this in the current std library. However, the future standard C++0x has an unique_ptr, which comes in replacement of auto_ptr, and which works with arrays.
A first implementation can be found here: unique_ptr
boost scoped_array or you can use boost scoped_ptr with a custom deleter
Not in STL. Boost has some smart pointers with a similar idea. Check out scoped_array and shared_array