If you modify your API a little bit, you could avoid this memory leak:
void DemPreLoad::LoadDemData_Area( std::vector< short int > & crop )
{
crop.resize( _Terrian_Range * _Terrian_Range * 4, 0 );
// ...
}
void DemPreLoad::LoadDemData_Area( std::vector< short int > & crop )
{
crop.resize( _Terrian_Range * _Terrian_Range * 4, 0 );
// ...
}
To copy to clipboard, switch view to plain text mode
or
std::vector< short int > DemPreLoad::LoadDemData_Area( )
{
std::vector< short int > crop( _Terrian_Range * _Terrian_Range * 4, 0 );
// ...
return crop;
}
std::vector< short int > DemPreLoad::LoadDemData_Area( )
{
std::vector< short int > crop( _Terrian_Range * _Terrian_Range * 4, 0 );
// ...
return crop;
}
To copy to clipboard, switch view to plain text mode
And of course you would have to modify your calling code to use a vector instead of a pointer to an array, but since vector overloads operator[] you can access the members of the vector using crop[ i ] in exactly the same way as if you had "crop" defined as an int * pointer and used crop[ i ]. If you actually need to access the vector as a pointer to an array, then &(crop[0]) returns that pointer.
Bookmarks