Suggestion 1
This block of code does not seem clean:
// Check whether the parameter is already full
if (data != 0){
// Reset the output
data->clear();
data = 0;
}
If data used to point to non-NULL, then you are just making it NULL. You should delete [] data before pointing it to NULL:
if (data != 0){
// Reset the output
data->clear();
delete data;
data = 0;
}
Suggestion 2
Still better, if you have the option, change the interface to
void readNParseData(const char* filePath, vector<double>& data);
Suggestion 3
There is nothing in your code to indicate to the calling function that you were able or unable to read the data from the file. There is no else to go with
if (ifs) {
One way of indicating whether the function was successful in reading the data is to change the return type of the function to bool. Then, you can add
return true;
at the end of the if block and then add an else block:
else {
return false;
}
Suggestion 4
To remove the redundant memory allocation and deallocation to fileBuffer, simply use std::vector::data:
data.resize(sizeOfBuffer);
ifs.read(reinterpret_cast<char*>(data.data()), fileSize);
Suggestion 5
Add a check to make sure that ifs.read was successful:
ifs.read(reinterpret_cast<char*>(data.data()), fileSize);
if ( !ifs )
{
return false;
}