fix malloc papapapam

This commit is contained in:
andrew (from workstation) 2020-05-22 11:11:50 +02:00
parent 050ad6283e
commit fb94a5f5d8
2 changed files with 41 additions and 21 deletions

View File

@ -3833,39 +3833,60 @@ void FileManager::memory_cleanup() {
} }
/* DESTROY INVALID file_hash_to_file_id_ */ /* DESTROY INVALID file_hash_to_file_id_ */
for (const auto &pair : file_hash_to_file_id_) { {
auto &file = file_id_info_[pair.second.fast_get()]; auto it = file_hash_to_file_id_.begin();
if (&file == nullptr || file_nodes_[file.node_id_] == nullptr) { while (it != file_hash_to_file_id_.end()) {
file_hash_to_file_id_.erase(pair.first); auto &file = file_id_info_[it->second.fast_get()];
if (file_nodes_[file.node_id_] == nullptr) {
file_hash_to_file_id_.erase(it);
} else {
it++;
}
} }
} }
/* DESTROY INVALID local_location_to_file_id_ */ /* DESTROY INVALID local_location_to_file_id_ */
for (const auto &pair : local_location_to_file_id_) { {
auto &file = file_id_info_[pair.second.fast_get()]; auto it = local_location_to_file_id_.begin();
if (&file == nullptr || file_nodes_[file.node_id_] == nullptr) { while (it != local_location_to_file_id_.end()) {
local_location_to_file_id_.erase(pair.first); auto &file = file_id_info_[it->second.fast_get()];
if (file_nodes_[file.node_id_] == nullptr) {
it = local_location_to_file_id_.erase(it);
} else {
it++;
}
} }
} }
/* DESTROY INVALID generate_location_to_file_id_ */ /* DESTROY INVALID generate_location_to_file_id_ */
for (const auto &pair : generate_location_to_file_id_) { {
auto &file = file_id_info_[pair.second.fast_get()]; auto it = generate_location_to_file_id_.begin();
if (&file == nullptr || file_nodes_[file.node_id_] == nullptr) { while (it != generate_location_to_file_id_.end()) {
generate_location_to_file_id_.erase(pair.first); auto &file = file_id_info_[it->second.fast_get()];
if (file_nodes_[file.node_id_] == nullptr) {
it = generate_location_to_file_id_.erase(it);
} else {
it++;
}
} }
} }
/* DESTROY INVALID remote_location_info_ */ /* DESTROY INVALID remote_location_info_ */
for (const auto &pair : remote_location_info_.get_map()) { {
auto &file = file_id_info_[pair.first.file_id_.fast_get()]; auto map = remote_location_info_.get_map();
if (&file == nullptr || file_nodes_[file.node_id_] == nullptr) { auto it = map.begin();
remote_location_info_.erase_map_key(pair.first, pair.second); while (it != map.end()) {
auto &file = file_id_info_[it->first.file_id_.fast_get()];
if (file_nodes_[file.node_id_] == nullptr) {
map.erase(it);
remote_location_info_.erase(it->second);
} else {
it++;
}
} }
} }
file_hash_to_file_id_.rehash(0); file_hash_to_file_id_.rehash(0);
file_id_info_.shrink_to_fit(); file_id_info_.shrink_to_fit();
empty_file_ids_.shrink_to_fit(); empty_file_ids_.shrink_to_fit();
empty_node_ids_.shrink_to_fit(); empty_node_ids_.shrink_to_fit();

View File

@ -19,8 +19,8 @@ class Enumerator {
public: public:
using Key = int32; using Key = int32;
std::map<ValueT, int32> get_map() const { std::map<ValueT, int32> &get_map() const {
return map_; return *map_;
} }
std::pair<Key, bool> next() { std::pair<Key, bool> next() {
@ -33,10 +33,9 @@ class Enumerator {
return std::make_pair((Key) (arr_.size() + 1), false); return std::make_pair((Key) (arr_.size() + 1), false);
} }
void erase_map_key(ValueT key_x, Key key_y) { void erase(Key key_y) {
auto pos_y = static_cast<Key>(key_y - 1); auto pos_y = static_cast<Key>(key_y - 1);
empty_id_.push_back(key_y); empty_id_.push_back(key_y);
map_.erase(key_x);
arr_[pos_y] = nullptr; arr_[pos_y] = nullptr;
} }