From 00289cd2224bbf3bbb8568f52a73e52596bd8e6e Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 6 Jul 2019 17:18:43 +0200 Subject: 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 --- qt-models/diveplotdatamodel.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'qt-models') diff --git a/qt-models/diveplotdatamodel.cpp b/qt-models/diveplotdatamodel.cpp index c8f086867..d89ab6f31 100644 --- a/qt-models/diveplotdatamodel.cpp +++ b/qt-models/diveplotdatamodel.cpp @@ -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(); } -- cgit v1.2.3-70-g09d2