Skip to content

Add "MemoryStrategy" to Executor with dep. injection#56

Merged
jacquelinekay merged 6 commits intomasterfrom
memory_dependency_injection
Jul 15, 2015
Merged

Add "MemoryStrategy" to Executor with dep. injection#56
jacquelinekay merged 6 commits intomasterfrom
memory_dependency_injection

Conversation

@jacquelinekay
Copy link
Copy Markdown
Contributor

This pull request introduces the MemoryStrategy class to delegate memory management on the execution path of Executor.

By default, MemoryStrategy is stateless and handles all delegated functions with dynamic memory management (malloc, free, new), but all functions are overrideable. An example subclass of MemoryStrategy, StaticMemoryStrategy, shows how these functions can be overridden and state can be added to implement fully static memory management.

The following functions are delegated to MemoryStrategy:

borrow_handles: returns a pointer to memory reserved for subscription, service, client or guard condition handles.
return_handles: cleans up memory instantiated in borrow_handles, by deleting it or resetting to NULL.
instantiate_next_executable: instantiates the next AnyExecutable object and passes it as a shared pointer.

In order to manage circular dependencies, I moved the AnyExecutable struct from a protected member of Executor to its own header file.

An example of how the memory strategy can be specified dynamically is in the examples/memory_dependency_injection:
https://github.com/ros2/examples/blob/memory_dependency_injection/rclcpp_examples/src/topics/listener_exec.cpp

@jacquelinekay jacquelinekay added the in progress Actively being worked on (Kanban column) label Jul 13, 2015
@jacquelinekay jacquelinekay self-assigned this Jul 13, 2015
@jacquelinekay jacquelinekay added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Jul 13, 2015
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use the RCLCPP_MAKE_SHARED_DEFINITIONS macro here to add the static function make_shared to the AnyExecutable class.

@wjwwood
Copy link
Copy Markdown
Member

wjwwood commented Jul 13, 2015

+1

@jacquelinekay
Copy link
Copy Markdown
Contributor Author

Updates based on William's comments in 541385a:

use RCLCPP_MAKE_SHARED for shared pointer typedefs for new classes
namespace/struct newline placement
change map to unordered_map and reserve memory in constructor of StaticMemoryAllocator

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use auto.

@wjwwood
Copy link
Copy Markdown
Member

wjwwood commented Jul 13, 2015

Thanks @jacquelinekay, 541385a lgtm.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All those member variables should have a trailing underscore and no leading underscore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants