F
fermisoft
I have a strange problem in my project.
I have a class like this......
class CMsg
{
public:
void *m_body;
~CMsg()
{
delete m_body;
}
}
During the program execution pointers of different types are typecasted
and assigned to m_body. Some pointers meant for a single block (p= new
char) and few are pointers to array. (Memory was allocated by p = new
char[nSize]).
Memory deallocation happens in the destructor of CMsg by invoking
delete. This deallocation works only for deleting a single block of
memory. So, while trying to delete memory assosiated with pointer to
array, exception is thrown.
How to identify pointer to an array? and deallocate accordingly by
calling delete [] ?
I have a class like this......
class CMsg
{
public:
void *m_body;
~CMsg()
{
delete m_body;
}
}
During the program execution pointers of different types are typecasted
and assigned to m_body. Some pointers meant for a single block (p= new
char) and few are pointers to array. (Memory was allocated by p = new
char[nSize]).
Memory deallocation happens in the destructor of CMsg by invoking
delete. This deallocation works only for deleting a single block of
memory. So, while trying to delete memory assosiated with pointer to
array, exception is thrown.
How to identify pointer to an array? and deallocate accordingly by
calling delete [] ?