Skip to content

Commit

Permalink
Moemory improvement with shrink_to_fit (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
l00p3 authored Jun 26, 2024
1 parent 742077a commit a6c96ed
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cpp/kiss_icp/core/VoxelHashMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include <Eigen/Core>
#include <algorithm>
#include <limits>
#include <tuple>
#include <utility>
#include <vector>
Expand All @@ -42,18 +41,21 @@ std::vector<Eigen::Vector3d> VoxelHashMap::GetPoints(const std::vector<Voxel> &q
}
}
});
points.shrink_to_fit();
return points;
}

std::vector<Eigen::Vector3d> VoxelHashMap::Pointcloud() const {
std::vector<Eigen::Vector3d> points;
points.reserve(max_points_per_voxel_ * map_.size());
for (const auto &[voxel, voxel_block] : map_) {
points.reserve(map_.size() * static_cast<size_t>(max_points_per_voxel_));
std::for_each(map_.cbegin(), map_.cend(), [&](const auto &map_element) {
const auto &[voxel, voxel_block] = map_element;
(void)voxel;
for (const auto &point : voxel_block.points) {
points.push_back(point);
points.emplace_back(point);
}
}
});
points.shrink_to_fit();
return points;
}

Expand Down

0 comments on commit a6c96ed

Please sign in to comment.