Profile: dynamically allocate plot pressure data

All accesses to the pressure data were converted to use functions.
Therefore it is now rather trivial to dynamically allocate the
pressure array and just change the functions.

The only thing to take care of is the idiosyncratic memory
management. Make sure to free and copy the buffer in the
appropriate places.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-07-06 17:18:43 +02:00 committed by Dirk Hohndel
parent bef1eac7fa
commit 00289cd222
4 changed files with 19 additions and 7 deletions

View file

@ -167,7 +167,9 @@ void DivePlotDataModel::clear()
beginResetModel();
pInfo.nr = 0;
free(pInfo.entry);
pInfo.entry = 0;
free(pInfo.pressures);
pInfo.entry = nullptr;
pInfo.pressures = nullptr;
diveId = -1;
dcNr = -1;
endResetModel();
@ -179,9 +181,12 @@ void DivePlotDataModel::setDive(dive *d, const plot_info &info)
diveId = d->id;
dcNr = dc_number;
free(pInfo.entry);
free(pInfo.pressures);
pInfo = info;
pInfo.entry = (struct plot_data *)malloc(sizeof(struct plot_data) * pInfo.nr);
pInfo.entry = (plot_data *)malloc(sizeof(plot_data) * pInfo.nr);
memcpy(pInfo.entry, info.entry, sizeof(plot_data) * pInfo.nr);
pInfo.pressures = (plot_pressure_data *)malloc(sizeof(plot_pressure_data) * MAX_CYLINDERS * pInfo.nr);
memcpy(pInfo.pressures, info.pressures, sizeof(plot_pressure_data) * MAX_CYLINDERS * pInfo.nr);
endResetModel();
}