Is it safe to use Microsoft specific _msize() function with new []?
Example:
int* i = new int[100];
size_t s = _msize(i);
cout << "Size of the array in bytes: " << s << endl;
delete [] i;
MSDN does describe just the usage with malloc & Co.
I've tested the code with Visual Studio 2010, and it looks to work! But i would like to know if there are some expected issues or any special cases?
There could be a problem if someone overrides operator new
for your type.
It is just as easy to write
const size_t s = 100;
int* i = new int[s];
or, if you really write C++
std::vector<int> i(100);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With