I have such code
#include <cstdlib>
class Foo
{
int m_data;
public :
Foo() : m_data(0) { }
/*~Foo()
{
}*/
static void* operator new[](const size_t size)
{
return malloc(size);
}
static void operator delete[](void* data)
{
free(data);
}
};
int main()
{
Foo* objects = new Foo[5];
delete [] objects;
}
In this case I receive value of size
in operator new overloading as 20 bytes as I wanted (sizeof(int) * 5
). But if I uncomment the destructor I get size
as 24 bytes. Yeah, I now that these extra bytes is used to store the size of allocated memory and equals to sizeof(size_t)
. I can't understand why I get them only if I implement destructor explicitly. If I don't do it, the compiler should do the exact same thing or I missing something?
I've tried that on MSVS 2010 and 2012. Compiled for Win32.