C
Cristiano
I use these two structures:
struct ROUTE {
char *name;
char *Pid;
char *Nid;
};
struct WPT {
char ID[6];
ROUTE *route;
};
and
std::vector <WPT *> wpt;
I do:
WPT *wp= new WPT; wpt.push_back(wp);
ROUTE *rou= new ROUTE; wp->route= rou;
rou->name= new char[strlen(RouteName) + 1];
strcpy(rou->name, RouteName);
and the same for Pid and Nid:
rou->Pid= new char[strlen(Pid+ 1]; strcpy(rou->Pid, Pid);
rou->Nid= new char[strlen(Nid+ 1]; strcpy(rou->Nid, Nid);
When I no longer need that stuff, I do:
for(int i= 0; i < wpt.size(); i++) {
if(wpt->route) {
delete[] wpt->route->name;
delete[] wpt->route->Pid;
delete[] wpt->route->Nid;
delete wpt->route;
}
delete wpt;
}
The debugger (I use Visual Studio 2008 EE) tell me that there is a
memory leak.
Is the deallocation procedure correct?
Thanks
Cristiano
struct ROUTE {
char *name;
char *Pid;
char *Nid;
};
struct WPT {
char ID[6];
ROUTE *route;
};
and
std::vector <WPT *> wpt;
I do:
WPT *wp= new WPT; wpt.push_back(wp);
ROUTE *rou= new ROUTE; wp->route= rou;
rou->name= new char[strlen(RouteName) + 1];
strcpy(rou->name, RouteName);
and the same for Pid and Nid:
rou->Pid= new char[strlen(Pid+ 1]; strcpy(rou->Pid, Pid);
rou->Nid= new char[strlen(Nid+ 1]; strcpy(rou->Nid, Nid);
When I no longer need that stuff, I do:
for(int i= 0; i < wpt.size(); i++) {
if(wpt->route) {
delete[] wpt->route->name;
delete[] wpt->route->Pid;
delete[] wpt->route->Nid;
delete wpt->route;
}
delete wpt;
}
The debugger (I use Visual Studio 2008 EE) tell me that there is a
memory leak.
Is the deallocation procedure correct?
Thanks
Cristiano