I have this situation where my program starts to slow down and eventually halts. I am guessing it is due to not claiming memory in a right way. Can anyone please help me what is the correct way to free memory in this case?
simplified definitions:
typedef struct {
std::string name;
std::vector<metric_t> metrics;
} region_t;
typedef struct {
std::string name;
std::vector<region_t> regions;
} data_t;
typedef struct {
std::string name;
std::vector<double> means;
} metric_t;
Main loop:
for(int i = 0; i < 100; i++)
{
data_t data;
prepare_data(&data);
/* Usage of data here */
}
prepare data function:
void prepare_data(data_t * data)
{
region_t new_region;
data->regions.push_back(new_region);
for(int j=0; j< 100000; j++)
{
metric_t new_metric;
/* put some data in new_metric */
data->regions.back().metrics.push_back(new_metric);
}
}