Is std::unique_ptr the wrong tool to allocate memory for an array?

Viewed 4556

I have an array of (for example) uint8_ts.

Is std::unique_ptr the wrong tool to use to manage this object in memory?

For example,

std::unique_ptr<uint8_t> data(new uint8_t[100]);

Will this produce undefined behaviour?

I want a smart-pointer object to manage some allocated memory for me. std::vector isn't ideal, because it is a dynamic object. std::array is no good either, because the size of allocation is not known at compile time. I cannot use the [currently, 2016-03-06] experimental std::dynarray, as this is not yet available on Visual Studio 2013.

Unfortunately I have to conform to VS2013, because, rules.

2 Answers
Related