我有以下代码用于创建包含结构图的结构图。我的问题是如何从 providerMap 中删除一个元素而不留下任何内存泄漏。我可以只做一个 providerMap[prov_id].erase() 还是我需要在第二个或更复杂的东西上做一个删除?
struct uriPrivs {
std::string name;
uchar properties;
};
struct providerValues {
int KeepAlive;
std::map<std::string /*uri*/, uriPrivs> uris;
};
std::map<std::string /*prov_id*/, providerValues> providerMap;
RISStorageManager::risStorageResponse RISStorageManager::update_provider(const std::string &prov_id, int KeepAlive) {
if (providerMap.find(prov_id) == providerMap.end()) {
providerValues x;
x.KeepAlive = KeepAlive;
providerMap[prov_id] = x;
return risStorageCreated;
} else {
providerMap[prov_id].KeepAlive = KeepAlive;
return risStorageUpdated;
}
}
RISStorageManager::risStorageResponse RISStorageManager::update_uri(const std::string &prov_id, std::map<std::string, uriPrivs> &uris) {
providerMap[prov_id].uris = uris;
}