Hi,
i am testing the function generateSp() which returns an array. The following code works. But when i run the prog for a long time (hours) i observe an incrementation of the used memory this ends with an "out of memory" :-(
What could be wrong in my code ?
#######################################
#include <iostream>
#define SP_SIZE 100
class CSp
{
public:
CSp();
~CSp();
CSp& operator=(const CSp &);
private:
double * const p;
};
CSp::CSp(): p(new double[SP_SIZE])
{
cout << "const:" << p << endl;
}
CSp::~CSp()
{
cout << "destr:" << p << endl;
delete []p;
}
CSp & CSp:
perator=(const CSp& right)
{
cout << "assignment operator begin" << endl;
for(int i = 0 ; i < SP_SIZE; i++ )
{
p = right.p;
}
return *this;
};
CSp generateSp()
{
cout << "generateSp" << endl;
CSp * p_spLocal = new CSp;
cout << "generated Local CSp" << endl ;
return * p_spLocal;
};
int main()
{
cout << "prog start" << endl;
while(1)
{
CSp spA;
cout << "generated spA" << endl;
spA = generateSp();
cout << "generateSp, assigned it to A" << endl;
}
return 0;
}
i am testing the function generateSp() which returns an array. The following code works. But when i run the prog for a long time (hours) i observe an incrementation of the used memory this ends with an "out of memory" :-(
What could be wrong in my code ?
#######################################
#include <iostream>
#define SP_SIZE 100
class CSp
{
public:
CSp();
~CSp();
CSp& operator=(const CSp &);
private:
double * const p;
};
CSp::CSp(): p(new double[SP_SIZE])
{
cout << "const:" << p << endl;
}
CSp::~CSp()
{
cout << "destr:" << p << endl;
delete []p;
}
CSp & CSp:
{
cout << "assignment operator begin" << endl;
for(int i = 0 ; i < SP_SIZE; i++ )
{
p = right.p;
}
return *this;
};
CSp generateSp()
{
cout << "generateSp" << endl;
CSp * p_spLocal = new CSp;
cout << "generated Local CSp" << endl ;
return * p_spLocal;
};
int main()
{
cout << "prog start" << endl;
while(1)
{
CSp spA;
cout << "generated spA" << endl;
spA = generateSp();
cout << "generateSp, assigned it to A" << endl;
}
return 0;
}