Created
October 15, 2015 01:04
-
-
Save jacquelinekay/723d8c2e03efbae39bbb to your computer and use it in GitHub Desktop.
allocator template example in rclcpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename MessageT, template<typename> class Alloc = std::allocator> | |
class Publisher : public PublisherBase | |
{ | |
// ... | |
Alloc<MessageT> message_allocator_; | |
// Publisher doesn't have any STL structures, but suppose it did (or think about the case for services): | |
std::vector<AnotherType, Alloc<AnotherType>> my_vector_; | |
// ... | |
void my_function() { | |
// instead of MessageT * msg = new MessageT; | |
MessageT * msg = std::allocator_traits<Alloc<MessageT>>::allocate(message_allocator_, 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment