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
|
@ -21,6 +21,7 @@ struct plot_info {
|
|||
double endtempcoord;
|
||||
double maxpp;
|
||||
struct plot_data *entry;
|
||||
struct plot_pressure_data *pressures; /* MAX_CYLINDERS blocks of nr entries. */
|
||||
};
|
||||
|
||||
extern struct divecomputer *select_dc(struct dive *);
|
||||
|
|
|
@ -501,7 +501,6 @@ static void insert_entry(struct plot_info *pi, int idx, int time, int depth, int
|
|||
entry->sec = time;
|
||||
entry->depth = depth;
|
||||
entry->running_sum = prev->running_sum + (time - prev->sec) * (depth + prev->depth) / 2;
|
||||
memset(entry->pressure, 0, sizeof(entry->pressure));
|
||||
entry->sac = sac;
|
||||
entry->ndl = -1;
|
||||
entry->bearing = -1;
|
||||
|
@ -510,6 +509,7 @@ static void insert_entry(struct plot_info *pi, int idx, int time, int depth, int
|
|||
void free_plot_info_data(struct plot_info *pi)
|
||||
{
|
||||
free(pi->entry);
|
||||
free(pi->pressures);
|
||||
pi->entry = NULL;
|
||||
}
|
||||
|
||||
|
@ -534,6 +534,7 @@ static void populate_plot_entries(struct dive *dive, struct divecomputer *dc, st
|
|||
nr = dc->samples + 6 + maxtime / 10 + count_events(dc);
|
||||
plot_data = calloc(nr, sizeof(struct plot_data));
|
||||
pi->entry = plot_data;
|
||||
pi->pressures = calloc(nr * MAX_CYLINDERS, sizeof(struct plot_pressure_data));
|
||||
if (!plot_data)
|
||||
return;
|
||||
pi->nr = nr;
|
||||
|
|
|
@ -28,11 +28,16 @@ struct deco_state;
|
|||
struct divecomputer;
|
||||
struct plot_info;
|
||||
|
||||
/*
|
||||
* sensor data for a given cylinder
|
||||
*/
|
||||
struct plot_pressure_data {
|
||||
int data[NUM_PLOT_PRESSURES];
|
||||
};
|
||||
|
||||
struct plot_data {
|
||||
unsigned int in_deco : 1;
|
||||
int sec;
|
||||
/* One pressure item per cylinder and pressure type */
|
||||
int pressure[MAX_CYLINDERS][NUM_PLOT_PRESSURES];
|
||||
int temperature;
|
||||
/* Depth info */
|
||||
int depth;
|
||||
|
@ -104,12 +109,12 @@ extern int get_maxdepth(struct plot_info *pi);
|
|||
|
||||
static inline int get_plot_pressure_data(const struct plot_info *pi, int idx, enum plot_pressure sensor, int cylinder)
|
||||
{
|
||||
return pi->entry[idx].pressure[cylinder][sensor];
|
||||
return pi->pressures[cylinder * pi->nr + idx].data[sensor];
|
||||
}
|
||||
|
||||
static inline void set_plot_pressure_data(struct plot_info *pi, int idx, enum plot_pressure sensor, int cylinder, int value)
|
||||
{
|
||||
pi->entry[idx].pressure[cylinder][sensor] = value;
|
||||
pi->pressures[cylinder * pi->nr + idx].data[sensor] = value;
|
||||
}
|
||||
|
||||
static inline int get_plot_sensor_pressure(const struct plot_info *pi, int idx, int cylinder)
|
||||
|
|
|
@ -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
Reference in a new issue