lcm-proj / lcm

Lightweight Communications and Marshalling
GNU Lesser General Public License v2.1
980 stars 388 forks source link

Removed implicit string conversion from const char* to std::string during subscription handling #314

Closed edrumwri closed 4 years ago

edrumwri commented 4 years ago

Simply adds a member to Subscription for storing the string and passes the string back to the callback handler.

Fixes #313


This change is Reviewable

ashuang commented 4 years ago

Thanks for the suggestion. This patch won't work because the "channel" passed into subscribe can be a regex, and may not correspond to the actual channel. However, I think we could achieve your goal of no heap allocation with the following changes:

  1. Add the std::string channel to the Subscription type. Reserve size LCM_MAX_CHANNEL_NAME_LENGTH during construction.
  2. In each handler, copy the actual channel into subs->channel.
edrumwri commented 4 years ago

Hi @ashuang - would you please take a look at the updated PR?