Rosanswers logo

If I have a subscriber with a buffer size of 10, and my callback has dealt with 3 messages, is there a way to access the number of messages left in the queue ( retrieve the value of 7 )?

Basically I want my subscriber to deal with a batch of messages, and then do some task once they have all come through, then deal with the next batch of messages, and then do the task again. I do not know the size of the batch of messages.

Ideally I just need an indication that the buffer is empty.

Originally posted by Grim on ROS Answers with karma: 31 on 2016-12-06

Post score: 2


1 Answer 1


Rosanswers logo

Push your messages shared_ptr to another data structure as they come in (such as std::queue), and do your batch processing there instead.

The inner workings of the ROS subscriber's message buffer are not exposed through the roscpp API.

Originally posted by paulbovbel with karma: 4518 on 2016-12-06

This answer was ACCEPTED on the original site

Post score: 0

Original comments

Comment by Grim on 2016-12-07:
While I think this may be a solution, I don't know how to do it. I have not dealt with std::shared_ptr or std::queue. And I am not sure if learning it right now would be worth my time for this project. This also needs to be memory efficient since the messages themselves are quite large.

Comment by paulbovbel on 2016-12-07:
You'd be pushing the boost::shared_ptr to the message (as received by your callback, ConstPtr) to the queue, so memory impact would be negligible.

If you're going to work with C++, I suggest becoming very familiar with the basics of std, particularly containers (http://en.cppreference.com/w/)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.