File tree Expand file tree Collapse file tree 2 files changed +27
-7
lines changed
include/mola_input_rosbag2 Expand file tree Collapse file tree 2 files changed +27
-7
lines changed Original file line number Diff line number Diff line change @@ -144,10 +144,11 @@ class Rosbag2Dataset : public RawDataSourceBase,
144
144
/* * At initialization
145
145
*
146
146
*/
147
- std::vector<std::optional<DatasetEntry>> read_ahead_;
148
- size_t rosbag_next_idx_ = 0 ;
149
- size_t rosbag_next_idx_write_ = 0 ;
150
- std::set<std::string> already_pub_sensor_labels_;
147
+ mutable std::vector<std::optional<DatasetEntry>> read_ahead_;
148
+ size_t rosbag_next_idx_ = 0 ;
149
+ size_t rosbag_next_idx_write_ = 0 ;
150
+ std::set<std::string> already_pub_sensor_labels_;
151
+ mutable std::deque<size_t > unload_queue_; // !< read_ahead_ indices
151
152
152
153
// Methods and variables for the ROS->MRPT conversion
153
154
// -------------------------------------------------------
@@ -200,6 +201,8 @@ class Rosbag2Dataset : public RawDataSourceBase,
200
201
201
202
Obs catchExceptions (const std::function<Obs()>& f);
202
203
204
+ void autoUnloadOldEntries () const ;
205
+
203
206
bool findOutSensorPose (
204
207
mrpt::poses::CPose3D& des, const std::string& target_frame,
205
208
const std::string& source_frame,
Original file line number Diff line number Diff line change @@ -531,9 +531,6 @@ void Rosbag2Dataset::spinOnce()
531
531
}
532
532
}
533
533
534
- // Free memory in read-ahead buffer:
535
- read_ahead_.at (rosbag_next_idx_).reset ();
536
-
537
534
// Move on:
538
535
rosbag_next_idx_++;
539
536
}
@@ -575,6 +572,8 @@ void Rosbag2Dataset::doReadAhead(
575
572
576
573
for (size_t idx = startIdx; idx <= endIdx; idx++)
577
574
{
575
+ unload_queue_.push_back (idx); // mark as recently accessed
576
+
578
577
if (read_ahead_.at (idx).has_value ()) continue ; // already read:
579
578
580
579
// serialized data
@@ -598,6 +597,9 @@ void Rosbag2Dataset::doReadAhead(
598
597
}
599
598
}
600
599
600
+ // and also, unload() very old observations.
601
+ autoUnloadOldEntries ();
602
+
601
603
MRPT_END
602
604
}
603
605
@@ -984,3 +986,18 @@ Rosbag2Dataset::Obs Rosbag2Dataset::catchExceptions(
984
986
return {};
985
987
}
986
988
}
989
+
990
+ void Rosbag2Dataset::autoUnloadOldEntries () const
991
+ {
992
+ const size_t MAX_UNLOAD_LEN = std::max<size_t >(10 , 2 * read_ahead_length_);
993
+
994
+ // unload() very old observations.
995
+ while (unload_queue_.size () > MAX_UNLOAD_LEN)
996
+ {
997
+ const auto idx = unload_queue_.front ();
998
+ unload_queue_.erase (unload_queue_.begin ());
999
+
1000
+ // Free memory in read-ahead buffer:
1001
+ read_ahead_.at (idx).reset ();
1002
+ }
1003
+ }
You can’t perform that action at this time.
0 commit comments