M
Moonrie Aurum
I have allocated a chunk of memory in the Contour::AddCurve() method as
below:
LPTTPOLYCURVE pCur=reinterpret_cast<LPTTPOLYCURVE>(new BYTE[n]);
Later in the destructor how can I free this new BYTE[n] memory block?
For some reason, I can not remain a LPBYTE pointor like: LPBYTE p= new
BYTE[n];
Can I do it like this:
delete [] reinterpret_cast<LPBYTE>(pCur);
Help me!
class Contour
{
public:
typedef std::vector<LPTTPOLYCURVE> ContourType;
Contour(){}
~Contour()
{
typedef std::vector<LPTTPOLYCURVE>::const_iterator itr;
for(itr i=_curves.begin(); i!=_curves.end(); i++)
{
//int n=sizeof(TTPOLYCURVE)+sizeof(POINTFX)*((*i)->cpfx -1);
LPBYTE p=reinterpret_cast<LPBYTE>(*i);
delete[] p;
}
}
void AddCurve(const TTPOLYCURVE& cur)
{
int n=sizeof(TTPOLYCURVE) + sizeof(POINTFX)*(cur.cpfx -1);
memcpy(pCur, &cur, n);
_curves.push_back(pCur);
}
private:
POINTFX _pfx;
// std::vector<Segment> _seg;
std::vector<LPTTPOLYCURVE> _curves;
};
below:
LPTTPOLYCURVE pCur=reinterpret_cast<LPTTPOLYCURVE>(new BYTE[n]);
Later in the destructor how can I free this new BYTE[n] memory block?
For some reason, I can not remain a LPBYTE pointor like: LPBYTE p= new
BYTE[n];
Can I do it like this:
delete [] reinterpret_cast<LPBYTE>(pCur);
Help me!
class Contour
{
public:
typedef std::vector<LPTTPOLYCURVE> ContourType;
Contour(){}
~Contour()
{
typedef std::vector<LPTTPOLYCURVE>::const_iterator itr;
for(itr i=_curves.begin(); i!=_curves.end(); i++)
{
//int n=sizeof(TTPOLYCURVE)+sizeof(POINTFX)*((*i)->cpfx -1);
LPBYTE p=reinterpret_cast<LPBYTE>(*i);
delete[] p;
}
}
void AddCurve(const TTPOLYCURVE& cur)
{
int n=sizeof(TTPOLYCURVE) + sizeof(POINTFX)*(cur.cpfx -1);
memcpy(pCur, &cur, n);
_curves.push_back(pCur);
}
private:
POINTFX _pfx;
// std::vector<Segment> _seg;
std::vector<LPTTPOLYCURVE> _curves;
};