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_ */
for (const auto &pair : file_hash_to_file_id_) {
auto &file = file_id_info_[pair.second.fast_get()];
if (&file == nullptr || file_nodes_[file.node_id_] == nullptr) {
file_hash_to_file_id_.erase(pair.first);
{
auto it = file_hash_to_file_id_.begin();
while (it != file_hash_to_file_id_.end()) {
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_ */
for (const auto &pair : local_location_to_file_id_) {
auto &file = file_id_info_[pair.second.fast_get()];
if (&file == nullptr || file_nodes_[file.node_id_] == nullptr) {
local_location_to_file_id_.erase(pair.first);
{
auto it = local_location_to_file_id_.begin();
while (it != local_location_to_file_id_.end()) {
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_ */
for (const auto &pair : generate_location_to_file_id_) {
auto &file = file_id_info_[pair.second.fast_get()];
if (&file == nullptr || file_nodes_[file.node_id_] == nullptr) {
generate_location_to_file_id_.erase(pair.first);
{
auto it = generate_location_to_file_id_.begin();
while (it != generate_location_to_file_id_.end()) {
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_ */
for (const auto &pair : remote_location_info_.get_map()) {
auto &file = file_id_info_[pair.first.file_id_.fast_get()];
if (&file == nullptr || file_nodes_[file.node_id_] == nullptr) {
remote_location_info_.erase_map_key(pair.first, pair.second);
{
auto map = remote_location_info_.get_map();
auto it = map.begin();
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_id_info_.shrink_to_fit();
empty_file_ids_.shrink_to_fit();
empty_node_ids_.shrink_to_fit();

View File

@ -19,8 +19,8 @@ class Enumerator {
public:
using Key = int32;
std::map<ValueT, int32> get_map() const {
return map_;
std::map<ValueT, int32> &get_map() const {
return *map_;
}
std::pair<Key, bool> next() {
@ -33,10 +33,9 @@ class Enumerator {
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);
empty_id_.push_back(key_y);
map_.erase(key_x);
arr_[pos_y] = nullptr;
}