I was overloading a delete operator in C++, I used free()
for this:
class A
{
private:
int x;
int y;
public:
void operator delete(void* ptr)
{
free(ptr);
}
void operator delete[](void* ptr)
{
free(ptr);
}
}
int main()
{
A *a = new A();
A *b = new A[10];
delete a; // This should free 8 bytes
delete b; // This also 8 only
delete[] b;// This should free 80 bytes
return 0;
}
how free do this job
As I know dynamic allocation store what size allocated as hidden so while deallocation it use from there
but when we use delete b;
or delete[] b;
hidden allocation says alwyas 80 then how 8 only get de-allocated.
If its not correct way then how we can overload delete operator using free?