mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
bef1eac7fa
commit
00289cd222
4 changed files with 19 additions and 7 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue